9.6 Example: ledButton
/* ledButton.
This script will cause an LED to turn on when a
push-button switch is pressed. The LED is attached to pin 13
and the button is attached to pin 7. */
#define LED 13
#define BUTTON 7
int val=0;
void setup() {
pinMode(LED, OUTPUT);
pinMode(BUTTON, INPUT);
}
void loop() {
val=digitalRead(BUTTON);
if (val == HIGH){
digitalWrite(LED, HIGH);
else
digitalWrite(LED, LOW);
}
}