//detect switch closure //and count how many time the switch got hit //NOTE: this code is "broken" //10/15/2008 BitMonkey Labs // int inputPin=7; //int outputPin=13; int counter=0; int lastSwitchState=LOW; void setup() { pinMode(inputPin, INPUT); // pinMode(outputPin, OUTPUT); Serial.begin(57600); } void loop() { //Serial.println(lastSwitchState); 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); //YUP! THIS THING IS TOTALLY WACKY! LOOKS LIKE IT COUNTED A LOT MORE SWITCH CLOSURES THEN IT SHOULD HAVE! //check the next example for how to take care of that problem. Also read up on "switch bounce"! }