Last active
November 25, 2019 10:13
-
-
Save likersacademia/6170ee8e46562b50342a66ef987752af 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
//03_hikari_led | |
//暗くなってから5秒たつと光り、その間に明るくなったら光らない | |
//SchooMyとかいてあるところまですすもう | |
#define cdsPin 5 | |
#define ledPin 10 | |
#define ON LOW | |
#define OFF HIGH | |
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 "); | |
//SchooMy | |
//プログラムはここからかえます | |
if (lux < 10) { //このエリアになったら | |
count++; //カウントする | |
Serial.print( count ); //表示する | |
Serial.println("秒"); //表示する | |
} else { //それ以外は | |
count = 0; //カウントをゼロにする | |
digitalWrite(ledPin, OFF); //光らない | |
} | |
if (count >= 5) { //この時間がたったら | |
digitalWrite(ledPin, ON); //光る | |
} else { //それ以外は | |
digitalWrite(ledPin, OFF); //光らない | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment