Created
July 8, 2019 07:11
-
-
Save surinoel/d851a18bbf843872e14187545f06ee97 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
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