Created
December 29, 2015 15:44
-
-
Save vim13/9327191953014190af1d to your computer and use it in GitHub Desktop.
Arduinoを始めよう 第二版 Massimo Banzi O'REILLY p.41
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
const int LED = 12; | |
const int BUTTON = 7; | |
int val = 0; | |
int old_val = 0; | |
int state = 0; | |
void setup() { | |
pinMode(LED, OUTPUT); | |
pinMode(BUTTON, INPUT); | |
} | |
void loop() { | |
val = digitalRead(BUTTON); | |
if ((val == HIGH) && (old_val == LOW)) { | |
state = 1 - state; | |
delay(10); | |
} | |
old_val = val; | |
if (state == 1) { | |
digitalWrite(LED, HIGH); | |
} else { | |
digitalWrite(LED, LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment