Created
August 22, 2019 01:05
-
-
Save likersacademia/be0288535e721e08a813abda73342e0f 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
/*DAYs SCENE 11 ★★★☆ | |
できること) | |
リモコンを取ってから、5秒たつまでに戻さないと注意される | |
最初に使うもの) | |
光センサー LED | |
仕組み) | |
ものの下に光センサーを置いておいて、上のものを取ると明るくなります。その明るさを読み取ります。 | |
*/ | |
#define cdsPin A5 //INPUTA:5 INPUTB:0 | |
#define ledPin 10 //OUTPUTA:5 OUTPUT:10 | |
#define ON LOW | |
#define OFF HIGH | |
#define SPEAKER 10 | |
#define do 262 | |
#define re 294 | |
#define mi 330 | |
#define fa 349 | |
#define so 392 | |
#define ra 440 | |
#define shi 494 | |
#define do2 523 | |
int count = 0; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(cdsPin, INPUT); | |
pinMode(ledPin, 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 "); | |
//プログラムは、ここから変更することをオススメします | |
/*スクーミーで、作って、問題解決をしよう! | |
先ずは、センサーがなにかを見て、それに対してお知らせする方法を考えてみよう。 | |
最初は全て、「明かりがつく」で設定してあります。 | |
明かりがついて教えてくれるのか | |
音で教えてくれるのか | |
どちらの方がいいか考えて、文字を変更してみよう。 | |
(本当は、ここの文章より上も変更するのですが、練習なので、ここの文章より下だけを変えることで動きます。) | |
明かりをつけて知らせたい場合 | |
digitalWrite(ledPin,ON); → LEDに明かりをつける | |
delay(1000); →その動作を何秒するか。1000で1秒 | |
digitalWrite(ledPin,OFF); → LEDの明かりを消す | |
delay(1000); →その動作を何秒するか。1000で1秒 | |
音を鳴らして知らせたい場合 | |
tone(SPEAKER,do); → ドの音(do:ド re:レ mi:ミ fa:ファ so:ソ ra:ラ shi:シ do2:ド ) | |
delay(1000); →その動作を何秒するか。1000で1秒 | |
noTone(SPEAKER); →音を止める | |
delay(1000); →その動作を何秒するか。1000で1秒 | |
明かりも音も両方使うこともできますが、上の文章の変更をする必要があります。 | |
*/ | |
if (lux > 30) { | |
count++; | |
Serial.println( count ); | |
}else{ | |
count=0; | |
digitalWrite(ledPin,OFF ); | |
delay(10); | |
} | |
if (count > 5){ | |
digitalWrite(ledPin, ON); | |
delay(10); | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment