Created
May 18, 2017 15:01
-
-
Save niloy-barua/c06efddb850ede5e90e2216d8f507aee to your computer and use it in GitHub Desktop.
Arduino : Switch Press&Release
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
void setup() | |
{ | |
pinMode(3,INPUT_PULLUP); | |
pinMode(13,OUTPUT); | |
} | |
void loop() | |
{ | |
//the following block of code will check a NO button switch for press & release | |
//---------------------------------------------------------------------------------- | |
bool buttonReleased=false; | |
if(!digitalRead(3)) | |
{ | |
while(!buttonReleased) | |
{ | |
delay(2); //delay added to avoid switch bouncing problem | |
if(digitalRead(3)) buttonReleased = true; | |
} | |
} | |
//---------------------------------------------------------------------------------- | |
//things to do only when button is released | |
//here we blink a LED 5 times | |
if(buttonReleased) | |
{ | |
for(byte i=0;i<5;i++) | |
{ | |
digitalWrite(13,HIGH); | |
delay(500); | |
digitalWrite(13,LOW); | |
delay(500); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment