Created
June 21, 2017 12:57
-
-
Save endlessdev/cea6a984fc990924bc7198e0464a4870 to your computer and use it in GitHub Desktop.
WTH 수행평가
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
#define BUTTON1 3#define BUTTON2 4#define BUTTON3 5 | |
#define LED1 9#define LED2 10#define LED3 11 | |
#define BUZZER 2 | |
bool buttonFlag = false; | |
void setup(){ | |
Serial.begin(9600); pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); pinMode(BUTTON1, INPUT_PULLUP); pinMode(BUTTON2, INPUT_PULLUP); pinMode(BUTTON3, INPUT_PULLUP); pinMode(BUZZER, OUTPUT); | |
attachInterrupt(digitalPinToInterrupt(BUTTON1), onButtonChanged, FALLING); attachInterrupt(digitalPinToInterrupt(BUTTON2), onButtonChanged, FALLING); attachInterrupt(digitalPinToInterrupt(BUTTON3), onButtonChanged, FALLING);} | |
void onButtonChanged(){ if(buttonFlag) return; | |
bool isClickedFirst = !digitalRead(BUTTON1); bool isClickedSecond = !digitalRead(BUTTON2); bool isClickedThird = !digitalRead(BUTTON3); | |
if(isClickedFirst){ Serial.println("clicked 1"); digitalWrite(LED1, HIGH); tone(BUZZER, 200, 1000); } if (isClickedSecond){ Serial.println("clicked 2"); digitalWrite(LED2, HIGH); tone(BUZZER, 300, 1000); } if (isClickedThird){ Serial.println("clicked3"); digitalWrite(LED3, HIGH); tone(BUZZER, 400, 1000); } buttonFlag = true;} | |
void loop(){ if(buttonFlag){ delay(4000); digitalWrite(LED1, LOW); digitalWrite(LED2,LOW); digitalWrite(LED3, LOW); noTone(BUZZER); buttonFlag = false; }} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment