Last active
December 17, 2015 15:39
-
-
Save pastak/5633025 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| int LED_ports[] = {6,9,11}; | |
| int speakerPort = 3; | |
| int switchPort = 2; | |
| boolean is_presentation = false; | |
| boolean is_question = false; | |
| boolean is_end = false; | |
| boolean is_waiting = true; | |
| int LED_Selector = 0; | |
| int timer; | |
| int presentationTime = 5 * 1000; | |
| int questionTime = 3 * 1000; | |
| int endTime; | |
| int switchVal = 1; | |
| int switchOldVal = 1; | |
| void initialize(void); | |
| void Beep(int time); | |
| void LED_Blink(boolean is_on); | |
| //LED 引数 true => on false => off | |
| void LED_Blink(boolean is_on){ | |
| int status = is_on ? LOW:HIGH; | |
| digitalWrite(LED_ports[LED_Selector],status); //LED点灯 | |
| } | |
| //音鳴らし用 | |
| void Beep(int time=100){ | |
| //tone(port , Hz , Time) | |
| tone(speakerPort,440,time); | |
| delay(time); | |
| } | |
| //初期化用関数 | |
| void initialize(void){ | |
| endTime = presentationTime + questionTime; | |
| LED_Selector = 0; | |
| timer = 0; | |
| is_presentation = true; | |
| digitalWrite(LED_ports[0],HIGH); | |
| digitalWrite(LED_ports[1],HIGH); | |
| digitalWrite(LED_ports[2],HIGH); | |
| } | |
| void setup(){ | |
| pinMode(speakerPort,OUTPUT); | |
| pinMode(LED_ports[0],OUTPUT); | |
| pinMode(LED_ports[1],OUTPUT); | |
| pinMode(LED_ports[2],OUTPUT); | |
| pinMode(switchPort,INPUT); | |
| digitalWrite(LED_ports[0],HIGH); | |
| digitalWrite(LED_ports[1],HIGH); | |
| digitalWrite(LED_ports[2],HIGH); | |
| //initialize(); | |
| } | |
| void loop(){ | |
| //スイッチがオンなら初期化する | |
| switchVal = digitalRead(switchPort); | |
| if((switchVal == LOW) && (switchOldVal == HIGH)){ | |
| if(is_waiting){ | |
| initialize(); | |
| is_waiting = false; | |
| }else{ | |
| is_waiting = true; | |
| } | |
| } | |
| //プレゼンテーション時間中の挙動 | |
| if(is_presentation){ | |
| LED_Blink(true); | |
| //プレゼン終了時刻なら質問時間へ | |
| if(presentationTime <= timer){ | |
| Beep(); | |
| is_presentation = false; | |
| is_question = true; | |
| LED_Blink(false); | |
| LED_Selector += 1; | |
| } | |
| //質問時間中の挙動 | |
| }else if(is_question){ | |
| LED_Blink(true); | |
| if(endTime <= timer){ | |
| Beep(); | |
| Beep(1000); | |
| LED_Blink(false); | |
| is_question = false; | |
| is_end = true; | |
| LED_Selector += 1; | |
| } | |
| }else if(is_end){ | |
| LED_Blink(true); | |
| } | |
| delay(10); | |
| timer += 10; | |
| switchOldVal = switchVal; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment