Created
June 24, 2019 07:18
-
-
Save likersacademia/6d1b2d3a1386ad08a06fcf9ddde237ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 光センサー、スピーカーの組み合わせで、プログラミングを学ぶ | |
#define cdsPin 5 | |
#define SPEAKER 5 | |
void setup() { | |
Serial.begin(9600); | |
pinMode(cdsPin, INPUT); | |
pinMode(SPEAKER, OUTPUT); | |
} | |
void loop() { | |
// R1のAD値を取得 | |
float cds_ad = analogRead(cdsPin); | |
// AD値を電圧値に変換 | |
float cds_v = cds_ad * 5 / 1023; | |
// 電圧値より、Lux計算 | |
float lux = 10000 * cds_v / (5 - cds_v) / 1000; | |
Serial.print(lux); | |
Serial.println(" Lux "); | |
//プログラムはここからかえます// | |
if (lux > 20) { | |
Serial.println("HIGH lux"); | |
delay(200); | |
} else { | |
Serial.println("LOW lux"); | |
delay(200); | |
} | |
//プログラムはここからかえます// | |
if (lux > 30) { // 2)数字をシリアルモニターを参考にして数字をかえよう | |
tone(SPEAKER,330) ; // 1) 数字をかえよう | |
delay(200); // 1) 数字をかえよう | |
noTone(SPEAKER); | |
delay(200); // 1) 数字をかえよう | |
tone(SPEAKER,200) ; // 1) 数字をかえよう | |
delay(200); // 1) 数字をかえよう | |
noTone(SPEAKER); | |
delay(200); // 1) 数字をかえよう | |
tone(SPEAKER,330) ; // 1) 数字をかえよう | |
delay(200); // 1) 数字をかえよう | |
noTone(SPEAKER); | |
delay(200); // 1) 数字をかえよう | |
tone(SPEAKER,200) ; // 1) 数字をかえよう | |
delay(200); // 1) 数字をかえよう | |
} else { | |
noTone(SPEAKER); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment