Created
March 23, 2014 12:52
-
-
Save pral2a/9722671 to your computer and use it in GitHub Desktop.
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 pushButton = 3; | |
int lastButtonState = 0; | |
boolean isOn = false; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(pushButton, INPUT); | |
lastButtonState = digitalRead(pushButton); | |
} | |
void loop() { | |
int buttonState = digitalRead(pushButton); | |
if (buttonState == HIGH && lastButtonState != buttonState) { | |
Serial.println("TRIGGER"); | |
if(isOn) { | |
isOn = false; | |
Serial.println("OFF"); | |
} | |
else { | |
isOn = true; | |
Serial.println("ON"); | |
} | |
} | |
lastButtonState = buttonState; | |
delay(1); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment