Hello everyone, I just took a year long hiatus from Arduino and I've forgotten everything I used to know. I'm trying to make a button turn on an LED for a random ammount of time but when I press the button, it flickes twice and turns off. The timing is the same every time and it only works propperly if i hold the button for a little while and then release it. Heres the code:
int pushButton = 2;
int LED = 13;
int buttonState = 7;
long randOn = 0;
long randOff = 0;
void setup() {
pinMode(pushButton, INPUT);
pinMode (LED, OUTPUT);
}
void loop() {
int buttonState = digitalRead(pushButton);
if (buttonState==HIGH)
{
randOn = random (100, 1200);
randOff = random (200, 900);
delay(100);
digitalWrite(LED, HIGH);
delay(randOn);
digitalWrite(LED, LOW);
delay(randOff);
}
}
Thanks,
Steve