heres one
uint8_t Switch = 2;
uint8_t Led =13;
boolean LedState =LOW;
int SwitchState =0;
int SwitchDebounce;
int LastSwitchState=HIGH;
int LastSwitchDebounce=LOW;
unsigned long LastDebounceTime = 0;
unsigned long DebounceDelay = 50;
void setup()
{
pinMode(Switch,INPUT);
digitalWrite(Switch,HIGH);
pinMode(Led,OUTPUT);
Serial.begin(9600);
}
void loop()
{
int CurrentSwitch = digitalRead(Switch);
if (CurrentSwitch != LastSwitchDebounce)
{
LastDebounceTime = millis();
}
if ((millis() - LastDebounceTime) > DebounceDelay)
{
SwitchState = digitalRead(Switch);
if (SwitchState != LastSwitchState)
{
if (SwitchState == LOW)
{
LedState = !LedState;
(LedState)?Serial.println("Led is On"):Serial.println("Led is Off");
}
}
LastSwitchState=SwitchState;
}
digitalWrite(Led,LedState);
LastSwitchDebounce = CurrentSwitch;
}