Skip to content

Instantly share code, notes, and snippets.

@surinoel
Created July 8, 2019 07:11
Show Gist options
  • Save surinoel/d851a18bbf843872e14187545f06ee97 to your computer and use it in GitHub Desktop.
Save surinoel/d851a18bbf843872e14187545f06ee97 to your computer and use it in GitHub Desktop.
int pinSwitch = 13;
int pinLed = 12;
int ledStatus = LOW;
int flag = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(pinSwitch, INPUT);
pinMode(pinLed, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(pinSwitch)) {
if(flag == 0) {
delay(20);
ledStatus = (ledStatus == LOW) ? HIGH : LOW;
digitalWrite(pinLed, ledStatus);
Serial.println("pushed");
flag = 1;
delay(20);
}
}
else {
flag = 0;
Serial.println("pulled");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment