LED Matrix Letter Writing [EASY]

hey there,
im newbie to arduino, and looking for some cool advise to go on with LED project. i want to write some letters on a simple LED Matrix i built, its 10x6 leds.
so far i created a code which says pixel by pixel which one goes on and of.
i am looking for a code that says " from pixel 0 to pixel 22 all pixels are black"

and next question would be if i can change the numbers of the led in which arduino is counting them, because i did not solder it clever, so it goes up and then down. is there a way to tell arduino to use led number 10 as 19 and 11 as 18, you know what i mean ?

here is my code

#include <FastLED.h>

#define LED_PIN     5
#define COLOR_ORDER GRB
#define CHIPSET     WS2811
#define NUM_LEDS    60
#define wait        3800

CRGB leds[NUM_LEDS];

void setup (){
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
}
void loop () {
  leds[0] = CRGB::Red;
  delay (wait);
    FastLED.show();
  leds[1] = CRGB::Black;
    leds[2] = CRGB::Black;
  leds[3] = CRGB::Black;
    leds[4] = CRGB::Black;
  leds[5] = CRGB::Black;
    leds[6] = CRGB::Black;
  leds[7] = CRGB::Black;
    leds[8] = CRGB::Black;
  leds[9] = CRGB::Black;
    leds[10] = CRGB::Black;
  leds[11] = CRGB::Black;
    leds[12] = CRGB::Black;
    leds[13] = CRGB::Black;
  leds[14] = CRGB::Black;
    leds[15] = CRGB::Black;
  leds[16] = CRGB::Black;
    leds[17] = CRGB::Black;
  leds[18] = CRGB::Black;
    leds[19] = CRGB::Red;
    delay (wait);
    FastLED.show();
  leds[20] = CRGB::Red;
     delay (wait);
    FastLED.show();

    leds[21] = CRGB::Black;
  leds[22] = CRGB::Black;
    leds[23] = CRGB::Black;
    leds[24] = CRGB::Black;
  leds[25] = CRGB::Black;
    leds[26] = CRGB::Black;
  leds[27] = CRGB::Black;
    leds[28] = CRGB::Black;
  leds[29] = CRGB::Black;
    leds[30] = CRGB::Black;
  leds[31] = CRGB::Black;
    leds[32] = CRGB::Black;
  leds[33] = CRGB::Black;
    leds[34] = CRGB::Black;
    leds[35] = CRGB::Black;
  leds[36] = CRGB::Black;
    leds[37] = CRGB::Black;
  leds[38] = CRGB::Black;
    leds[39] = CRGB::Red;
  delay (wait);
    FastLED.show();

  leds[40] = CRGB::Red;
    delay (wait);
    FastLED.show();

   leds[41] = CRGB::Black;
    leds[42] = CRGB::Black;
  leds[43] = CRGB::Black;
    leds[44] = CRGB::Black;
    leds[45] = CRGB::Black;
  leds[46] = CRGB::Black;
    leds[47] = CRGB::Black;
  leds[48] = CRGB::Black;
    leds[49] = CRGB::Black;
  leds[50] = CRGB::Black;
    leds[51] = CRGB::Black;
  leds[52] = CRGB::Black;
    leds[53] = CRGB::Black;
  leds[54] = CRGB::Black;
    leds[55] = CRGB::Black;
    leds[56] = CRGB::Black;
  leds[57] = CRGB::Black;
    leds[58] = CRGB::Black;
  leds[59] = CRGB::Red;
     delay (wait);
    FastLED.show();

    leds[60] = CRGB::Black;
        leds[0] = CRGB::Black;
        leds[19] = CRGB::Black;
           leds[20] = CRGB::Black;
              leds[39] = CRGB::Black;
                 leds[40] = CRGB::Black;
                    leds[59] = CRGB::Black;
  FastLED.show();
}

the matrix looks like this:

I suspect that what you need is a for loop.

kukaka1212:
i am looking for a code that says " from pixel 0 to pixel 22 all pixels are black"

  for (int i=0; i <= 22; i++) SetPixel(i, black);

kukaka1212:
and next question would be if i can change the numbers of the led in which arduino is counting them, because i did not solder it clever, so it goes up and then down. is there a way to tell arduino to use led number 10 as 19 and 11 as 18, you know what i mean ?

int PixelMap[60] = {0, 1, 2, 3, 4, 5, 6, 7 8, 9,
                             19, 18, 17, 16, 15, 14, 13, 12, 11, 10,
                              20, 21, 22, 23, 24, 25...

SetPixel(PixelMap[i], black);

+1 for maps!

I won’t admit to ever having used a map to correct a harder-to-fix-in-hardware problem, but certainly they can straighten out a zig zag neopixel array as @johnwasser shows.

a7

johnwasser:

  for (int i=0; i <= 22; i++) SetPixel(i, black);
int PixelMap[60] = {0, 1, 2, 3, 4, 5, 6, 7 8, 9,
                         19, 18, 17, 16, 15, 14, 13, 12, 11, 10,
                          20, 21, 22, 23, 24, 25...

SetPixel(PixelMap[i], black);

wow ok cool super! the "from this pixel to this pixel" code works super for me :slight_smile: YEAH! ROCK!
but i am wondering how to use the mapping function. maybe i have to tell my problem again:
i have soldered the leds not in a good poistion.
here is a picture of how i soldered it:


but i want to count it always from the button and not in line. you know what i mean ?
can i declare that in the beginning of the arduino session ? so arduino is reading the leds in the new way?

Every pixel has a number or “index” dictated by the wiring order in which they are wired.

Meanwhile you want them in another order.

Write the real numbers down in the order that you want them to seem like they are wired. This is the contents of the map array.

Then… whenever you want to refer to your pixel number N, send instead the Nth value from the map.

Look at @johnwasser’s example above closely you will see exactly that being done.

The pixel map array should be a global variable, and any time you ever want to talk about your pixel N, use map[N] in its stead.

You may need to learn a little bit about arrays. Trust us, it’s time.

a7

want to write some letters on a simple LED Matrix i built, its 10x6 leds.
so far i created a code which says pixel by pixel which one goes on and of.
i am looking for a code that says " from pixel 0 to pixel 22 all pixels are black"

For the letters, wouldn't you want to address the array by XY coordinates?

Yes! maps can be useful for thinking about 2D XY addressing also.

a7

hey a7,
thanks cool, i start to unterstand! now i added the pixelMap to my code, but it seems i forgot any {[]} or something like this ?
can you tell ?
its says:"scalar object 'PixelMap' requires one element in initializer"

#include <FastLED.h>

#define LED_PIN     5
#define COLOR_ORDER GRB
#define CHIPSET     WS2811
#define NUM_LEDS    60
#define wait        3800



CRGB leds[NUM_LEDS];

void setup (){
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  
int PixelMap = {0,1,2,3,4,5,6,7,8,9,
                19,18,17,16,15,14,13,12,11,10,
                20,21,22,23,24,25,26,27,28,29,
                39,38,37,36,35,34,33,32,31,30,
                40,41,42,43,44,45,46,47,48,49,
                59,58,57,56,55,54,53,52,51,50,
                60}
}
void loop () {
   for (int i=5; i <= 56; i++) {
    leds[i]= CRGB::Red;
   }
  delay (wait);
  leds[map[19]] = CRGB::Green;

  FastLED.show();

}

aarg:
For the letters, wouldn't you want to address the array by XY coordinates?

sure thing! if this is possible i would love to have it with coordinates, but i thought this would be way ahead my arduino skillz :wink:

ok the initializer problem i solve ! yippie!
now its saying:
"invalid types 'CRGB [60][long int(long int, long int, long int, long int, long int)]' for array subscript"
on this row: " leds[map[22]] = CRGB::Green;"

#include <FastLED.h>

#define LED_PIN     5
#define COLOR_ORDER GRB
#define CHIPSET     WS2811
#define NUM_LEDS    60
#define wait        3800



CRGB leds[NUM_LEDS];

void setup (){
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  
int PixelMap[] = {0,1,2,3,4,5,6,7,8,9,
                19,18,17,16,15,14,13,12,11,10,
                20,21,22,23,24,25,26,27,28,29,
                39,38,37,36,35,34,33,32,31,30,
                40,41,42,43,44,45,46,47,48,49,
                59,58,57,56,55,54,53,52,51,50,
                60};
}
void loop () {
   for (int i=5; i <= 56; i++) {
    leds[i]= CRGB::Red;
   }
  delay (wait);
  leds[map[22]] = CRGB::Green;

  FastLED.show();

}

it's a nice learning project, but before you invest to much time in re-inventing the wheel, I assume Adafruit has a ready library including writing to such a zig-zag neopixel display.

At a glance this

leds[map[22]] = CRGB::Green;

uses map, which appears nowhere, you probably want PixelMap[22]. Not sure why you didn’t get an error, perhaps map is defined somewhere not obvious.

edit: sry, I see I said use map, I shoulda said use the map, refer to by whatever name you give it, PixelMap in this case after @johnwasssee above…

Also, PixelMap must be global, move it outside you setup() function so it is available to everyone function that needs it.

@noiasxa, there may well be libraries handling every imaginable wiring and configuration of pixels, but there is something to be said for getting a handle on using a map, which concept can come in handy all over the place. Like wiring errors or non - standard arrangements, as you say a learning exercises.

a7

kukaka1212:
sure thing! if this is possible i would love to have it with coordinates, but i thought this would be way ahead my arduino skillz :wink:

Mmmm... how would you map characters without some kind of coordinate system? You can call it row, column instead of x,y but it amounts to the same thing. Have you not yet considered how you will display your characters?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.