Hi all,
I'm very new to arduino... very new. I have found a script I like online and modified it to suit my needs.
The design I have in mind is a dash light bar for a volunteer emergency responder that also has LED's in the tail lights that flash in an alternating pattern. Pins 4-12 are for the light bar and 2-3 are for the tail lights.
Here's where I need your help: I want to incorporate a momentary push button that turns the lights on and off (preferably a debounce one - that seems to be the better option).
Second thing I need is another signal input (pushbutton for the breadboard for now) that would turn off the outputs at pin 2 & 3 while the signal is detected, then when it goes back to 0 allow it to start flashing again.
The reason I want this is to have the lights in the tail lights stop flashing while the brake pedal is on. So for prototyping purpose I want to use a push button but in the future it'll be simply a signal in from the brake light wire.
Here's the code I have so far, any help would be much appreciated
// Timing suquences for the LED's in milliseconds
// First value is on time, second value is off time,
// third value on time and so on (up to 10 values)
// One row for each LED
unsigned int led_timing[][12] = {
{75, 75, 75, 225},
{0, 225, 75, 75, 75},
{50, 50, 50, 50, 50, 50, 50, 50, 50, 300},
{0, 300, 50, 50, 50, 50, 50, 50, 50, 50, 50},
{250, 250},
{75, 75, 75, 225},
{0, 225, 75, 75, 75},
{0, 250, 250},
{50, 50, 50, 50, 50, 50, 50, 50, 50, 300},
{0, 300, 50, 50, 50, 50, 50, 50, 50, 50, 50},
};
// The pins the LED's are connected to
byte led_pins[] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
// Keep track of timing sequence
// Array size taken from led_pins
unsigned long last_change[sizeof(led_pins)/sizeof(led_pins[0])];
byte timing_i[sizeof(led_pins)/sizeof(led_pins[0])];
void setup()
{
// Initialize LED's as output
for (byte i = 0; i < sizeof(led_pins)/sizeof(led_pins[0]); i++)
{
pinMode(led_pins[i], OUTPUT);
digitalWrite(led_pins[i], HIGH);
}
}
void loop()
{
// Current timestamp
unsigned long now = millis();
// Keep track of sequence for each LED
for (byte i = 0; i < sizeof(led_pins)/sizeof(led_pins[0]); i++)
{
if (now - last_change[i] >= led_timing[i][timing_i[i]])
{
digitalWrite(led_pins[i], !digitalRead(led_pins[i]));
timing_i[i]++;
// Start over at the end of timing sequence
timing_i[i] %= sizeof(led_timing[i])/sizeof(led_timing[i][0]);
last_change[i] = now;
}
}
}