some toggle code.
//zoomkat LED button toggle test 11-08-2012
int button = 5; //button pin, connect to ground as button
int press = 0;
boolean toggle = true;
void setup()
{
pinMode(13, OUTPUT); //LED on pin 13
pinMode(button, INPUT); //arduino monitor pin state
digitalWrite(5, HIGH); //enable pullups to make pin 5 high
}
void loop()
{
press = digitalRead(button);
if (press == LOW)
{
if(toggle)
{
digitalWrite(13, HIGH); // set the LED on
toggle = !toggle;
}
else
{
digitalWrite(13, LOW); // set the LED off
toggle = !toggle;
}
}
delay(500); //delay for debounce
}
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
byte oldPinState = HIGH;
void setup ()
{
pinMode (buttonPin, INPUT_PULLUP);
pinMode (ledPin, OUTPUT);
} // end of setup
void loop ()
{
byte pinState = digitalRead (buttonPin);
if (pinState != oldPinState)
{
delay (10); // debounce
if (pinState == LOW)
digitalWrite (ledPin, !digitalRead (ledPin)); // toggle pin
oldPinState = pinState; // remember new state
} // end of if pin state change
} // end of loop