Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niloy-barua/c06efddb850ede5e90e2216d8f507aee to your computer and use it in GitHub Desktop.
Save niloy-barua/c06efddb850ede5e90e2216d8f507aee to your computer and use it in GitHub Desktop.
Arduino : Switch Press&Release
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