Multiple led sequence over time

So the rows are represented the frames/seconds and the columns represented the leds state - led 1(index 0) is the far most right and led 64 (index 63) is far most left.

  1. can I make it a rows of only 60 bits (as the number of leds I will use) and not 64 ?
  2. so if my sequence is 5 minutes I gonna have an array of 300 lines and 60 columns?
    edit:
  3. so with the memory it taken for 300 hundreds line of 64 bit I actually make a sequence of 15 minutes (1500 lines), right?
  1. you could but I will expand it to 64 anyway as I will make an generic example with 64 LEDs. And it will have no effect on the memory, as each "line" occupies 64bit, regardless if you just define 0b0 or 60bit or full on with 0xFFFFFFFFFFFFFFFF
  2. yes. 300 lines at 1 second will give you a playtime of 5 minutes with 60 LEDs (64 are possible).
  3. let's try it, you could do the math on your own :wink: . There are some limits with low 64K (near/far) but this is not the point currently.

Thanks for try and help! I do hope it will work out

download from:
https://werner.rothschopf.net/microcontroller/202109_millis_led_sequence_en.htm

have fun.

Wow! Thank you very much. I did not run it yet but it seems promising.
Much appreciate your help! :slight_smile:

I was wandering if I can change the variable 'interval' to be different values in different frames/lines

for example between frame/line 1 to 10 to have an interval of 500 milliseconds and between lines 11 - 22 to have an interval of 1000 milliseconds , then between lines 100 - 150 to have a interval of 250 milliseconds.

Can I do so?
I guess I need to count some how the line I'm in and if the count is passed a specific line then change the interval to a different number.. possible?
edit:
something like that:

#endif
    actualPattern++;                       // switch to next pattern for the next iteration
    if (actualPattern >= totalNoPattern) 
      actualPattern = 0;                  // wrap around
     if (actualPattern > 10 && actualPattern < 20)
     {
      interval = 200;
     }
    previousMillis = millis();
  }
}

edit: I just needed to change the interval to be only int without a const and it seems to work fine!

make the interval a variable (remove the const)
ad some ifs to change the interval, someting like

if (actualPattern == 11) interval = 1000;
else if (actualPattern == 100) interval = 250;
else if (actualPattern == 0) interval = 100;  // don't forget to switch back to your start value...

and you don't need an int. int is signed and your interval will never get negative.

can I add a counter that counts how many leds are in on states at the same time and keep track of it? (adding and removing from and to count)
I would like to make sure no more then 18 leds will be on at the same time so I can drew from each led 10mA instead of 3mA I'm drawing right now. (due to arduino max 200mA current limitation)

come on, these are basics.

make a counter variable and increase its value in the if true (when you switch on a LED).
After the for loop you know how many IOs were set.

A better way would be a test function to be called once in setup, highlighting lines with to many LEDs. You do the correction of the array and upload a new sketch.

Make us proud of your learnings and show that you have understood the program.

I manage to change the interval time in different frames so its very good for me :slight_smile: I'm working now on the led_on_count variable

btw - what is that syntax of 'DEBUG_UART' next to the if function ?
I never encounter this before

do you see what's currently happening in the serial monitor?

Yes

then go to row 26 and change it to

#define DEBUG_UART 0

upload it again and see

I see. it activate and deactivate the debug monitor. Useful!

example:

#define DEBUG_UART 1

the precompiler will replace everywhere in the sketch the term DEBUG_UART with a 1

now if you see a

#if DEBUG_UART

the precompiler will get
#if 1
which translates to a "true" and will keep the lines in the source code.

if you change the DEBUG_UART to 0, the precompiler will "delete" the lines between #if and #endif - your program gets smaller because there is no need to print.

This explanation might not be 100% accurate but hopefully understandable.

read here: https://www.tutorialspoint.com/cplusplus/cpp_preprocessor.htm

I stuck with the count on led variable.

I manage to count how many leds on using 'ledCount++;' right after the 'digitalWrite (ledPin[I], HIGH);'

but then when I'm using 'ledCount--;' right after the 'digitalWrite(ledPin[I], LOW);' it count all the off leds.
I needs somehow to count only the leds that were previously on .

only count up.
don't count down.

I might not explain myself well
I want to count how many leds are on in a given time
so if in my first frame I had 2 leds on my counter will show 2.
in the next frame I have also 2 leds on so my counter should also show 2.

int the next frame I have 0 leds on so my count will show 0
and in the frame after I will have 10 leds on so my counter should show 10.

the counter will count the number of led are on at the same time in any given frame and will changed according to that.

imho just 4 lines of code:

void runSequence()
{
  static uint32_t previousMillis = 0;                  
  static size_t actualPattern = 0;                    
  byte noOfactiveLeds = 0; // create a variable
  if (millis() - previousMillis >= interval)          
  {
    // lets copy the actual pattern from progmem to a temporary local variable in SRAM
    patternType temp;
    memcpy_P(&temp, &pattern[actualPattern], sizeof(patternType));
    // now check each bit for each LED if it is 0 or 1 and switch the pin accordingly
    for (size_t i = 0; i < totalNoPins; i++)
    {
      if (temp & ((patternType)1 << i)) {           
#if DEBUG_UART
        Serial.print(F("X"));
#endif
        digitalWrite(ledPin[i], HIGH);
        noOfactiveLeds++; // increase counter
      }
      else {
#if DEBUG_UART
        Serial.print(F(" "));
#endif
        digitalWrite(ledPin[i], LOW);
      }
    }
#if DEBUG_UART
    Serial.print(F(" active LEDs="));     // NEW
    Serial.print(noOfactiveLeds);         // NEW
    Serial.print(F(" - "));
    Serial.println(actualPattern);
#endif