Last active
November 25, 2019 10:32
-
-
Save likersacademia/0bf94b89ba1def61297cbfccad2c4ce3 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_speaker | |
//動きが速いと、鳴る | |
//SchooMyとかいてあるところまですすもう | |
#define cdsPin 5 | |
#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 | |
double luxnew = 0; //新しい光の値 | |
double luxold = 0; //古い光の値 | |
double ans = 0; //差 | |
void setup() { | |
Serial.begin(9600); | |
pinMode(cdsPin, INPUT); | |
pinMode(SPEAKER, 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) { //この速さの間の時は | |
tone(SPEAKER, do); //鳴る | |
} else { //それ以外は | |
noTone(SPEAKER); //鳴らない | |
} | |
luxold = luxnew; | |
delay(50); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment