Go Down

Topic: How to modify this code to read the output from LEDMatrixStudio (Read 99 times) previous topic - next topic

ratherwok

Hi, last year with the help of some wonderful people in this forum I was able to write a code that addresses LEDs individually.

However it gets exhausting writing each color when I use a lot of LEDs. I found this wonder program LED Matrix Studio that exports code from a drawing program. It output $00 hex which I can easily replace with 0x so I can use it with FastLED.

However my code addresses LEDs is like
LED 1- frame 1, frame 2, frame 3...
LED 2- frame 1, frame 2, frame 3...
LED 3- frame 1, frame 2, frame 3...
......


I'm trying to modify it to be this so I can use the output from the LED Matrix Studio
frame 1 -LED 1, LED 2, LED 3...
frame 2 -LED 1, LED 2, LED 3...
frame 3 -LED 1, LED 2, LED 3...
......



Any help is appreciated!

Here's my code.

Code: [Select]
#include <FastLED.h>

#define NUM_LEDS 120
#define DATA_PIN 5
#define CLOCK_PIN 6

CRGB DOT[NUM_LEDS];

unsigned long previousMillis[NUM_LEDS] = {};
byte indexes[NUM_LEDS] = {0};
const byte MAX_NUM_OF_PERIODS =5;
long COLOR[][MAX_NUM_OF_PERIODS] =
{
  {0xFFFF00, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},
  {0xFF007F, 0x000000, 0x000000, 0x000000, -1},

  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},
  {0x000000, 0xFF007F, 0x000000, 0x000000, -1},

  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},
  {0x000000, 0x000000, 0xFF007F, 0x000000, -1},

  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
  {0x000000, 0x000000, 0x000000, 0xFF007F, -1},
};

int FR = 150;

void setup() {
  FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, BGR> (DOT, NUM_LEDS);
  FastLED.setBrightness(10);
}

void loop() {
  unsigned long currentMillis = millis();

 for(int LED = 0; LED < NUM_LEDS; LED++) {
  if(currentMillis - previousMillis[LED] >= FR) {
    DOT[LED] = COLOR[LED][indexes[LED]];
    FastLED.show();

    previousMillis[LED] = currentMillis;
    indexes[LED]++;
  }
  if (COLOR[LED][indexes[LED]] == -1) {
    indexes[LED] = 0;
  }
 }
}

david_2018

After rearranging the COLOR array, you just need to swap the indexes around when referencing the array.

COLOR[LED][indexes[LED]]

changes to

COLOR[indexes[LED]][LED]


If the COLOR array can be defined as constant, better to put it in program memory since it is so large.

See if this works the same as your original sketch:
Code: [Select]

#include <FastLED.h>

#define NUM_LEDS 120
#define DATA_PIN 5
#define CLOCK_PIN 6

CRGB DOT[NUM_LEDS];

unsigned long previousMillis[NUM_LEDS] = {};
byte indexes[NUM_LEDS] = {0};
const byte MAX_NUM_OF_PERIODS = 5;

const long COLOR[MAX_NUM_OF_PERIODS][NUM_LEDS] PROGMEM = {
  { 0xFFFF00, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000
  },
  { 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000
  },
  { 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000
  },
  { 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F
  },
  { -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1
  }
};

unsigned int FR = 150;

void setup() {
  FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, BGR> (DOT, NUM_LEDS);
  FastLED.setBrightness(10);
}

void loop() {
  unsigned long currentMillis = millis();

  for (int LED = 0; LED < NUM_LEDS; LED++) {
    if (currentMillis - previousMillis[LED] >= FR) {
      //      DOT[LED] = pgm_read_dword(&(COLOR[LED][indexes[LED]]));
      DOT[LED] = pgm_read_dword(&(COLOR[indexes[LED]][LED]));
      FastLED.show();
      previousMillis[LED] = currentMillis;
      indexes[LED]++;
    }
    //    if (pgm_read_dword(&(COLOR[LED][indexes[LED]])) == -1) {
    if (pgm_read_dword(&(COLOR[indexes[LED]][LED])) == -1) {
      indexes[LED] = 0;
    }
  }
}

ratherwok

After rearranging the COLOR array, you just need to swap the indexes around when referencing the array.

COLOR[LED][indexes[LED]]

changes to

COLOR[indexes[LED]][LED]


If the COLOR array can be defined as constant, better to put it in program memory since it is so large.

See if this works the same as your original sketch:
Code: [Select]

#include <FastLED.h>

#define NUM_LEDS 120
#define DATA_PIN 5
#define CLOCK_PIN 6

CRGB DOT[NUM_LEDS];

unsigned long previousMillis[NUM_LEDS] = {};
byte indexes[NUM_LEDS] = {0};
const byte MAX_NUM_OF_PERIODS = 5;

const long COLOR[MAX_NUM_OF_PERIODS][NUM_LEDS] PROGMEM = {
  { 0xFFFF00, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000
  },
  { 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000
  },
  { 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000
  },
  { 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F
  },
  { -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1
  }
};

unsigned int FR = 150;

void setup() {
  FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, BGR> (DOT, NUM_LEDS);
  FastLED.setBrightness(10);
}

void loop() {
  unsigned long currentMillis = millis();

  for (int LED = 0; LED < NUM_LEDS; LED++) {
    if (currentMillis - previousMillis[LED] >= FR) {
      //      DOT[LED] = pgm_read_dword(&(COLOR[LED][indexes[LED]]));
      DOT[LED] = pgm_read_dword(&(COLOR[indexes[LED]][LED]));
      FastLED.show();
      previousMillis[LED] = currentMillis;
      indexes[LED]++;
    }
    //    if (pgm_read_dword(&(COLOR[LED][indexes[LED]])) == -1) {
    if (pgm_read_dword(&(COLOR[indexes[LED]][LED])) == -1) {
      indexes[LED] = 0;
    }
  }
}


This code works perfectly! Thank you for typing all that. And I never knew about the flash memory, this just made my life so much easier. Thank you again for your help!

david_2018

If you don't have a need to have an individual timer on each LED, then the code can be made a bit more efficient.  The frame rate will need to be adjusted a bit, because the color of every LED is being updated before executing the FastLed.show() command, instead of doing it after each LED.

Code: [Select]

#include <FastLED.h>

#define NUM_LEDS 120
#define DATA_PIN 5
#define CLOCK_PIN 6

CRGB DOT[NUM_LEDS];

unsigned long currentMillis;
unsigned long previousMillis = 0;
byte index;
const byte MAX_NUM_OF_PERIODS = 4;

const long COLOR[MAX_NUM_OF_PERIODS][NUM_LEDS] PROGMEM = {
  { 0xFFFF00, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000
  },
  { 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000
  },
  { 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000
  },
  { 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
    0x000000, 0x000000, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F,
    0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F, 0xFF007F
  }
};

unsigned int FR = 500;

void setup() {
  FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, BGR> (DOT, NUM_LEDS);
  FastLED.setBrightness(10);
}

void loop() {
  currentMillis = millis();
  if (currentMillis - previousMillis >= FR) {
    previousMillis = currentMillis;
    for (byte LED = 0; LED < NUM_LEDS; LED++) {
      DOT[LED] = pgm_read_dword(&(COLOR[index][LED]));
    }
    FastLED.show();
    index++;
  }
  if (index >= MAX_NUM_OF_PERIODS) {
    index = 0;
  }
}

Go Up