Since many of the LEDs have a repeating pattern e.g. led 14, I'd look to find a way to just describe the first cycle and then repeat it until time is up.
Are you a non-programmer?
maybe a different approach will be to create around 8 - 16 sequence of no more then 30 seconds and to call them in different times using millis() ?
I'm very new in that field..
Aren't your sequences controlled by millis()? By the way, are you fixed in the pattern requirement, or can you creatively alter them to suit the application limitations?
to create a function for each led and call it in different times using millis?
for example led 8: light on for 1 sec then off for 8 sec. then to call it every 9 seconds?
no.. I don't know how to start even.. maybe to be focus on the first 5 leds?
Will you be writing this program?
got no choice
No, it would be hard to write and harder to debug. It needs to be data driven. Since you are new to this, the approach @anon57585045 suggests would probably suit you better.
What code have you tried? Have you lit up any LEDs yet? By the way, I may be pilloried for this, but you actually don't need millis()... not unless you have some other tasks to perform at the same time.
Yes I lit up a LEDS. I used delay and even millis() but I just not sure how I should start with so many leds and long sequence
Post the entire working sketch.
// background LED blinker example
#define MAX_BLINKERS 40 // maximum simultaneous background blinkers
struct // background blinker control data
{ uint8_t led_index; // 0..254, 255=not used indicator
uint16_t count; // number of blink cycles
uint16_t msec; // cycle time
uint32_t delay_ms; // delay before starting
uint16_t halfcycs; // count remaining
uint32_t tm; // half cycle timer
} bb[MAX_BLINKERS];
void setup()
{
for (uint8_t i=0; i < MAX_BLINKERS; i++) bb[i].led_index = 255; // mark not used
for (uint8_t i=2; i <= 12; i++) pinMode( i, OUTPUT ); // LED output pins
}
// control the LED hardware
void setLED( uint8_t led_index, boolean on_off )
{
digitalWrite( 2+led_index, on_off ); // LEDs are on consecutive pins from pin 2...
}
// start a background blinker
void backgndBlink( uint8_t led_index, uint16_t cycles, uint16_t cycle_msec, uint16_t initial_delay_msec )
{
// find unused entry
uint8_t i;
for (i=0; i < MAX_BLINKERS; i++) if (bb[i].led_index == 255) break;
if (i >= MAX_BLINKERS) return; // no space left, ignore blinker request
// copyin control parms
bb[i].led_index = led_index;
bb[i].count = cycles;
bb[i].msec = cycle_msec/2; // 50% duty cycle
bb[i].delay_ms = initial_delay_msec;
// init blinker state
bb[i].tm = millis();
bb[i].halfcycs = cycles*2;
if (bb[i].delay_ms == 0) setLED(led_index,true); // start blink'n
}
// run the background blinkers
boolean backgndYield() // returns true if any blinkers are active
{
boolean blink_active = false;
for (uint8_t i=0; i < MAX_BLINKERS; i++)
if (bb[i].led_index != 255) // blinker active?
{ blink_active = true;
if (bb[i].delay_ms) // in initial delay period?
{ if (millis() - bb[i].tm >= bb[i].delay_ms)
{ bb[i].delay_ms = 0; // end delay period
bb[i].tm = millis();
setLED(bb[i].led_index,true); // start blink'n
}
}
else if (millis() - bb[i].tm >= (uint32_t)(bb[i].msec))
if (--bb[i].halfcycs == 0)
bb[i].led_index = 255; // end blinker
else // blink
{ bb[i].tm = millis();
setLED( bb[i].led_index, !(bb[i].halfcycs & 1) );
}
}
return blink_active;
}
// use this instead of delay() to run the backgnd blinkers
void backgndDelay( uint16_t msec )
{
for (uint32_t tm = millis(); millis() - tm < (uint32_t)msec; ) backgndYield();
}
void loop()
{
// start group of blinkers
backgndBlink( 0, 10, 1000, 0 ); // 10 cycles at 1 Hz rate
backgndBlink( 1, 20, 500, 4000 ); // 20 cycles at 2 Hz after 4 seconds
backgndBlink( 2, 10, 1000, 7000 ); // 10 cycles at 1 Hz rate 3 seconds later
backgndDelay( 5000 ); // delay 5 seconds
// start another group of blinkers
backgndBlink( 3, 10, 1000, 0 ); // 10 cycles at 1 Hz rate
backgndBlink( 4, 20, 500, 2000 ); // 20 cycles at 2 Hz after 2 seconds
backgndBlink( 5, 10, 1000, 8000 ); // 10 cycles at 1 Hz rate 6 seconds later
while (backgndYield()); // wait for all blinkers to end
}
this code works great with that amount of lines in the void loop(){}
the moment I add more 'gahlilit' function its starts to be stuck and act strange
Get an SD card reader. Save your Excel sheet as a .CSV file to the SD card. Write a sketch to read the .CSV file one line at a time and update the LEDs.
This is an extremely unconventional way to use millis(). Have you looked at a typical millis() driven application? There are numerous examples. Your program logic is unnecessarily complex.
Keep in mind that your basic flow is:
repeat {
get data
send to LEDs
wait some time interval
}
what is that repeat?
can you show an example with 2 leds pattern? I can't wrap my head around it...
Pseudocode. It just means repeat forever what is in the { }.
repeat {
get data 1,2
send to LEDs 1,2
wait some time interval
}
or more properly
repeat {
for i = 1 to 2 {
get data [i]
send to LED [i]
}
wait some time interval
}