//detect switch closure //and count how many time the switch got hit, this implements a more complex debouncing scheme //10/15/2008 BitMonkey Labs // int inputPin=7; //int outputPin=13; int lastSwitchState=LOW; int counter=0; unsigned long lastReadTime; void setup() { pinMode(inputPin, INPUT); //pinMode(outputPin, OUTPUT); Serial.begin(57600); lastReadTime=millis(); } void loop() { if((millis()-lastReadTime)>=200) //take a reading every 200 milliseconds { if((digitalRead(inputPin)==HIGH)&&(lastSwitchState==LOW)) //prevent switch from retriggering by just holding it down { counter++; //increment the counter variable every time switch is hit Serial.println(counter); } lastSwitchState=digitalRead(inputPin); lastReadTime=millis(); } }