Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//06_hikari_led
//動きが速いと光る
//SchooMyとかいてあるところまですすもう
#define cdsPin 5
#define ledPin 10 //OUTB
#define ON LOW
#define OFF HIGH
double luxnew = 0; //新しい光の値
double luxold = 0; //古い光の値
double ans = 0; //差
void setup() {
Serial.begin(9600);
pinMode(cdsPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
float cds_ad = analogRead(cdsPin);
// AD値を電圧値に変換
float cds_v = cds_ad * 5 / 1023;
// 電圧値より、Lux計算
luxnew = 10000 * cds_v / (5 - cds_v) / 1000;
Serial.print(luxnew);
Serial.println(" Lux ");
ans = luxnew - luxold;
//SchooMy
//プログラムはここからかえます
if (abs(ans) > 10) { //この速さの間の時は
digitalWrite(ledPin, ON); //光る
delay(200); //待つ
} else { //それ以外は
digitalWrite(ledPin, OFF); //光らない
delay(200); //待つ
}
luxold = luxnew;
delay(50);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment