Project Planning after a long hiatus

Hello,

I was recently gifted an Elegoo Mega2560 starter kit, and have an ambitious project in mind, but I am at this point unable to remember much from my EE microcontroller days spent over my HC11…

My final goal is to drive a set of LEDs under a sheet of lucite to make a map of sorts for a game board. I want to start simply by getting one to work, and then creating a different .ino file for each mission for each play of the game.

I ordered a set of WS2812B LEDs from Amazon, linked here:
Treedix WS2812B LEDs

After running through the lessons on the CD, I’ve found leaving the shallow end of the pool has a steep curve. Rather than posting a help me, I’ve tried to research the direction I want to go in. I’ve found this code from a tutorial (as well as posted here) as well as the FastLED website that has examples and command explanations.


#include <FastLED.h>

#define LED_PIN     7
#define NUM_LEDS    20

CRGB leds[NUM_LEDS];

void setup() {

  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  
}

void loop() {
  
  leds[0] = CRGB(255, 0, 0);
  FastLED.show();
  delay(500);  
  leds[1] = CRGB(0, 255, 0);
  FastLED.show();
  delay(500);
  leds[2] = CRGB(0, 0, 255);
  FastLED.show();
  delay(500);
  leds[5] = CRGB(150, 0, 255);
  FastLED.show();
  delay(500);
  leds[9] = CRGB(255, 200, 20);
  FastLED.show();
  delay(500);
  leds[14] = CRGB(85, 60, 180);
  FastLED.show();
  delay(500);
  leds[19] = CRGB(50, 255, 20);
  FastLED.show();
  delay(500);
}

My question is this: where would I find the information for setting up 8 individual rows of 7 LEDs in order to drive each output pin? The colors won’t be changing like I’ve seen in YouTube videos or on tutorials, and this code seems ok for a single row, but will get unwieldy for 8 rows. Does that make sense?

I don’t know what will be the most efficient way, but I intend on making as many mistakes as I can to figure out how not to do it.

Thank you in advance for any interest and/or helping me find my way.

If I am getting what you are saying, a 2 dimensional array like you are already using, the extra dimension (first) is the row something like

CRGB leds[ROWS][NUM_LEDS];
and using your code with row 4 would be
leds[3][0] = CRGB(255, 0, 0);
  FastLED.show();
where the 3 represents the 4th ROW (0,1,2,3)

There's no need to use multiple output pins. A single pin can handle all the LEDs. Mathematically speaking, the physical topology (rows/columns) doesn't have to be the same as the electrical topology (a straight line). You just snake that straight line back and forth into multiple rows. Does that make sense?

I find single dimension arrays easier to manage. You then have to translate an x,y position to an index into the LED array.

So for 7 rows of 8 columns, an arbitrary (column, row) position is found by

#define COLUMNS 8
#define ROWS  7

int leds[ROWS * COLUMNS];

// Find LED position defined by row, column
int i = row * ROWS  + column;

// Catch overflow
i = (i >= ROWS  * COLUMNS)  ?  ROWS  * COLUMNS-1 : i;
leds[i] = color...

Would that allow me to manually put each pixel into place? I had initially put loops out of my brain…

I guess I had invisioned something like:

Row0 (rgb,rgb,rgb,rgb,rgb,rgb,rgb,rgb)
Row1 (rgb,rgb,rgb,rgb,rgb,rgb,rgb,rgb)
….
Row7 (rgb,rgb,rgb,rgb,rgb,rgb,rgb,rgb)

And then just populating the pixels that I need to light, with 0’s everywhere else. Finally printing each row with the FastLED.show for each row?

Exactly.

To make it work, you'll probably have to break the LED strip at the end of each row and insert enough wire to provide space to place the next row. But as long as you have a daisy-chain of rows it will be fine. Just make sure that you have a big enough power supply to handle the max number of LEDs you expect to be on at once.

I originally had planned on different output pins because I wanted to run a data line as well as a buck converter in each row for power consumption reasons as well as making a wiring harness for each set. The Lucite is going to be a bit unforgiving when I do my wiring, and wanted to be able to pull a row when it fails.

I hadn’t thought of running them all in one snaking line, but it does seem to make sense now that it came from outside my brain…

Doing them on separate output lines should work as long as you create a separate LED object for each row. Personally, I'd find this harder to manage, but go with whatever works.

Im planning on using a Harley battery that will have more than enough cold cranking amps, limiting the 3A buck converters to 2A worth of draw, and provide enough juice to the Mega2560 to keep this lit for a weekend’s worth of 1 hour games that we don’t need to trip over a cord while we are circling around the table to move our pieces.

Would I still be able to run it as:

AllRows ( rgb, rgb, rgb, rgb, rgb, rgb, rgb,
rgb, rgb, rgb, rgb, rgb, rgb, rgb,
rgb, rgb, rgb, rgb, rgb, rgb, rgb,
rgb, rgb, rgb, rgb, rgb, rgb, rgb,
rgb, rgb, rgb, rgb, rgb, rgb, rgb,
rgb, rgb, rgb, rgb, rgb, rgb, rgb,
rgb, rgb, rgb, rgb, rgb, rgb, rgb,
rgb, rgb, rgb, rgb, rgb, rgb, rgb,)

Yes. Laying out the lines like that makes it easier to visualize for us, but to the compiler it's the same as one long line.

There's a way you can access a single array as a set of individual strips with CPixelView:

Small update:

I have one half of the board done and just taped down. My soldering skills are coming back. There’s a marked difference between my first and my last lol. Currently, I’m addressing each row separately (I just wanted to see some results). I’m happy with what I’ve done so far, but I know there’s a long road ahead of me. Thank you to everyone that has responded so far.


It’s a horrible picture as far as the wiring goes, I know… but there will be a better one when I make a jig to get my LEDs exactly the right distances apart.

1 Like