Last active
March 19, 2017 06:58
-
-
Save jyoshida-sci/3b55ec7d1e216e27e4fdc642ad98cacf 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
/* | |
* | |
State change detection (edge detection) | |
http://www.arduino.cc/en/Tutorial/ButtonStateChange | |
*/ | |
const int buttonPin = 3; | |
const int outPin = 13; | |
int buttonState = 0; | |
int lastButtonState = 0; | |
void setup() { | |
pinMode(buttonPin, INPUT); | |
pinMode(outPin, OUTPUT); | |
} | |
void loop() { | |
buttonState = digitalRead(buttonPin); | |
if (buttonState != lastButtonState) { | |
if (buttonState == HIGH){ | |
for(int i=0; i<171; i++ ){ | |
digitalWrite(outPin, HIGH); | |
delay(20); | |
digitalWrite(outPin, LOW); | |
delay(20); | |
} | |
} | |
delay(1000); | |
} | |
lastButtonState = buttonState; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment