Last active
August 29, 2015 14:16
-
-
Save tatsuro-ueda/6c5d082badcd6af8e1c0 to your computer and use it in GitHub Desktop.
ArduinoでLEDを点灯させるトグルスイッチのコード
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
int lightIsOn = LOW; | |
int switchIsWaiting = HIGH; | |
void setup() { | |
pinMode(13, OUTPUT); | |
} | |
void loop() { | |
if(digitalRead(12) == HIGH){ // スイッチが押されているなら | |
if(switchIsWaiting){ | |
if(lightIsOn){ | |
// 消灯 | |
lightIsOn = LOW; | |
digitalWrite(13, LOW); | |
} else { // 消灯しているなら | |
// 点灯 | |
lightIsOn = HIGH; | |
digitalWrite(13, HIGH); | |
} | |
switchIsWaiting = LOW; // スイッチは、もはや待機しない | |
} | |
} else { // スイッチが押されていない | |
switchIsWaiting = HIGH; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment