Last active
November 25, 2019 10:31
-
-
Save likersacademia/c6ada1fa99e722c509f2fb89bc4d136c 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
//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