In this task the light has to be turned on for only one second once the button is pressed, a bit like the self timed safety lights for houses - on for a short duration after being triggered.
#define LED 13 // pin for LED
#define BUTTON 7 //pin for switch
int val = 0; //setting the memory to 0
void setup(){
pinMode(LED, OUTPUT);
//setting the direction for the LED
pinMode(BUTTON, INPUT);
//setting the Button direction
}
void loop(){
val = digitalRead(BUTTON); //read the button
if (val == HIGH){ //if pressed set high
digitalWrite(LED,HIGH); //turn LED on
} else {
digitalWrite (LED, LOW); //turn led off
}
if (val == HIGH){ //if pressed delay
delay(1000);
}
}
I’m starting to get used to those double ==
This program is really straight forward and hinges around the use of the “if then else” statement although I note there does not seem to be a then part to the statement this seems to be assumed.
Each of these programs have been debugged and run on the arduino system so any typos that have come in are after testing.