I am sorry if this is a simple question but I've been working on this for days and I can't get it to work. I know about a thousand ways to get this not to work however. I've read multiple posts and have tried the approaches given there but no luck.
What I have is 3 separate LED's on pins 9,10,11 (analog) and a button on pin 2.
SETUP
Turn pin 9,10,11 on when the Arduino starts for 2 seconds (works good)- tests that everything is working
Turn off pins 10,11 and 9 glows
LOOP
Wait for the button to be pressed and flicker all the LED's for 6 seconds
Go back to 9 low value and 10, 11 off
I can't get the button to work. I've had it to where it wouldn't turn on the flicker and now the flicker runs continuously
// LED Fire Effect
unsigned long elapsedTime;
unsigned long onTime;
int helmleft = 10; // left side of helmet 10
int helmright = 11; //right side of helmet to 11
int chairtop = 9; //insulators on the top of the chair to 2
const int button = 2; //sets the button to 2
void setup()
{
onTime=millis();
onTime=elapsedTime;
pinMode(button, INPUT);
pinMode(helmleft, OUTPUT);
pinMode(helmright, OUTPUT);
pinMode(chairtop, OUTPUT);
analogWrite(helmleft, 250);
analogWrite(helmright, 250);
analogWrite(chairtop, 250);
delay(2000);
digitalWrite(button, HIGH);
analogWrite (chairtop, 5); // glow insulators
analogWrite (helmleft, 0); //helmet off
analogWrite (helmright, 0); //helmet off
}
void loop() {
if (digitalRead (button)==LOW);
{
changelights();
onTime = millis(); //should only turn on the lights if the button is pressed
}
if (onTime>0 && millis() - onTime>6000) {
analogWrite (chairtop, 5);
analogWrite (helmleft, 0);
analogWrite (helmright, 0);
onTime=0; //keeps the helmet off and the insulators glowing
}
}
void changelights() { //flicker effect of LED's
analogWrite(helmleft, random (0,200));
analogWrite(helmright, random (0,200));
analogWrite(chairtop, random (0,200));
delay (random (10,100));
}