Skip to content

Instantly share code, notes, and snippets.

@jyoshida-sci
Last active March 19, 2017 06:58
Show Gist options
  • Save jyoshida-sci/3b55ec7d1e216e27e4fdc642ad98cacf to your computer and use it in GitHub Desktop.
Save jyoshida-sci/3b55ec7d1e216e27e4fdc642ad98cacf to your computer and use it in GitHub Desktop.
/*
*
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