I want the LED to flash when I press the switch once, but it keeps flashing. I tried the idea of just lighting the LED and keeping it lit with just one button press, so I wrote:
int led=13,button=12;
void setup() {
pinMode(led,OUTPUT);
pinMode(button,INPUT);
}
void loop() {
if (digitalRead(button)==HIGH)
digitalWrite(led,HIGH);
}
and this worked; it stayed on after I pressed the button once, so for the flashing LED I wrote:
int led=13,button=12;
void setup() {
pinMode(led,OUTPUT);
pinMode(button,INPUT);
}
void loop() {
if (digitalRead(button)==HIGH)
{
digitalWrite(led,HIGH);
delay(1000);
digitalWrite(led,LOW);
delay(1000);
} }
but this didn't work. It stops flashing after I remove my hand from the switch. Why is this happening?
{}
tags to format your code properly. Make sure it's indented properly too. You also need to fix capitalisation in your title and in your post for legibility and credibility. Your compiler wouldn't let you away with it. Why should we? Note that your question has no electrical design element to it so it will probably be moved to the Arduino StackExchange site.