//detect switch closure //and count how many time the switch got hit, this implements a very simple debouncing scheme //10/15/2008 BitMonkey Labs // int inputPin=7; //int outputPin=13; int lastSwitchState=LOW; int counter=0; void setup() { pinMode(inputPin, INPUT); //pinMode(outputPin, OUTPUT); Serial.begin(57600); } void loop() { if(digitalRead(inputPin)==HIGH) { delay(200); //wait for the plate bounce to settle and read again if((digitalRead(inputPin)==HIGH)&&(lastSwitchState==LOW)) //prevent switch from retriggering by just holding it down //in engineerese we are performing "edge detection" { counter++; //increment the counter variable every time switch is hit Serial.println(counter); } lastSwitchState=digitalRead(inputPin); } }