Hello I am new to arduino and programming and I am having trouble with some code. The goal is when I press and hold the button the two LED will blink at different times going back and forth and if the button is not press it will remain off. However when I run the code the LED's turn on by themselves without me pressing the button and runs as though I was. When I press the button the LED's stop blinking and stay on. I am not sure what I did wrong can anyone give me some advice.
Here is the code
const int LY=9;
const int LR=10;
const int BUTTON=11;
const int fade=10;
int ButtonState =0;
void setup() {
pinMode(LY, OUTPUT);
pinMode(LR, OUTPUT);
pinMode(BUTTON, INPUT);
}
void loop() {
ButtonState = digitalRead(BUTTON);
if(ButtonState == HIGH)
{
digitalWrite(LY, LOW);
delay(100);
digitalWrite(LY, HIGH);
delay(fade);
digitalWrite(LR, LOW);
delay(100);
digitalWrite(LR, HIGH);
delay(fade);
}
else if(ButtonState == LOW)
{
digitalWrite(LY, LOW);
digitalWrite(LR, LOW);
}
}