Hi, I’m trying to do the following:
Press push button once
White LED flashes 4 times
After the last flash 3 LEDs (green, red, and yellow) run through a fade sequence together for about 10 seconds
Then everything off until button is pressed again.
Currently when my nano is powered the green, red and yellow LED start fading straight away, when the button is pressed they go static on and the white LED flashes then the fade starts again for ever. I’ve tried adding ‘if button high’ with a delay before the fade section but didn’t work and I also added
‘analogWrite(xx LOW)’ in setup and loop section. Neither worked.
My code is as follows. Any help would be greatly appreciated.
//resemble starting fire with flint
//white led flashing to show flint and steel followed by fire effect LED
const int bb = 2;
// push button connected to pin 2 with 10k pull down resistor
const int wled = 9;
// white LED connected to pin 9 270ohm resistor
int rled = 5;
// LED red connected to pin 5 270ohm resistor
int yled = 6;
// LED yellow connected to pin 6 270ohm resistor
int gled = 3;
// LED green connected to pin 3 270ohm resistor
int bbs = 0; // push button state
void setup() {
// nothing happens in setup
pinMode(wled, OUTPUT);
pinMode(bb, INPUT);
}
void loop() {
bbs = digitalRead(bb);
if (bbs == HIGH) {
digitalWrite(wled, HIGH);
delay(100);
digitalWrite(wled, LOW);
delay(1000);
digitalWrite(wled, HIGH);
delay(100);
digitalWrite(wled, LOW);
delay(1000);
digitalWrite(wled, HIGH);
delay(100);
digitalWrite(wled, LOW);
delay(1000);
digitalWrite(wled, HIGH);
delay(100);
digitalWrite(wled, LOW);
delay(1000);
}
// fade in from min to max in increments of 5 points:
for (int fadeValue = 155; fadeValue <= 255; fadeValue += 50) {
// sets the value (range from 0 to 255):
analogWrite(rled, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
for (int fadeValue = 0; fadeValue <= 100; fadeValue += 50) {
// sets the value (range from 0 to 255):
analogWrite(yled, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(10);
}
for (int fadeValue = 0; fadeValue <= 6; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(gled, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(10);
}
// fade out from max to min in increments of 5 points:
for (int fadeValue = 255; fadeValue >= 200; fadeValue -= 50) {
// sets the value (range from 0 to 255):
analogWrite(rled, fadeValue);`Use code tags to format code for the forum`
// wait for 30 milliseconds to see the dimming effect
delay(100);
}
for (int fadeValue = 160; fadeValue >= 0; fadeValue -= 50) {
// sets the value (range from 0 to 255):
analogWrite(yled, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
for (int fadeValue = 6; fadeValue >= 0; fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(gled, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(100);
}
}