Good day amazing community,
First, a few words about my project so you can have a better understanding at what I want so you can help me easier:
Project:
I'm trying to recreate a police lightbar for 1/43 miniature cars. this lightbar have about 8 LEDS: 2 are blue only and 6 can either flash in blue (emergency mode) or yellow (traffic advisor). here is a video example
My issue
Following a lot of research, i was able to come up with the following code to turn on / off multiple LEDS using a custom flashing pattern using millis().
However, although this code is great for one color LED, it may not be the best one for RGB led, therefore:
Could anyone provide any assistance on how to optimize it for RGB led ? I know blue is: 0b001 and yellow is: 0b110, but I don't know wether i should do something in the array or in the function where i set the LED state to either HIGH or LOW
const uint16_t PINS[] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
const uint16_t PINS_NO = sizeof(PINS) / sizeof(PINS[0]);
struct seq_entry
{
uint16_t pattern;
uint32_t interval;
};
uint32_t lastIntervalChangeTime = 0;
uint32_t intervalLength;
const seq_entry HST_SEQUENCE[] = {
{0B0000000011, 1000},
{0B0000111111, 1000},
{0B1111111111, 1000},
{0B0000000000, 500},
{0B1111111111, 500},
{0B0000000000, 500},
{0B1111111111, 500},
{0B0000000000, 500},
{0B1111111111, 3000},
{0B1111111100, 500},
{0B1111000000, 500},
{0B0000000000, 1500}
};
const uint16_t HST_SEQUENCE_NO = sizeof(HST_SEQUENCE) / sizeof(HST_SEQUENCE[0]);
uint16_t hst_sequence_index = 0; //controls which step of the sequence it starts on
void hstSequence()
{
for ( int i = 0; i < PINS_NO; i++ )
{
if ((HST_SEQUENCE[hst_sequence_index].pattern & (0x1 << i)) != 0)
{
level = HIGH;
}
else
{
level = LOW;
}
digitalWrite(PINS[i], level );
}
intervalLength = HST_SEQUENCE[hst_sequence_index].interval;
hst_sequence_index++;
if ( hst_sequence_index == HST_SEQUENCE_NO )
{
hst_sequence_index = 0;
}
//intervalLength = HST_SEQUENCE[hst_sequence_index].interval;
} // End of void hstSequence
Thank you very much for taking the time to read and help