Presently this is just the code required to get a push-to-make input to latch and LED on and off. A full explanation will follow.
Code
/*
* by Joshua Maxey
* created 26/03/2013
*
* requirements:
* - 1 x LED (with suitable resistor)
* - 1 x switch (push to make, non latching)
*
* instructions for this sketch can be found at the following URL:
*
*
**************************************/
int led = 11;
int button = 13;
void setup() {
pinMode(led, OUTPUT);
pinMode(button, INPUT_PULLUP);
//we will use the serial port to alert us once the setup function has finished
Serial.begin(9600);
Serial.println("setup is complete");
}
void loop() {
//if the button is pushed and the LED is off
if (digitalRead(button) == LOW && digitalRead(led) == LOW) {
//turn it on
digitalWrite(led, HIGH);
Serial.println("LED is on");
delay(200);
}
//if the button is pushed and the LED is on
if (digitalRead(button) == LOW && digitalRead(led) == HIGH) {
//turn it off
digitalWrite(led, LOW);
Serial.println("LED is off");
delay(200);
}
}