I created a program to display a scrolling text (variable width) on an LED grid (8x32). The code below displays the message variable content of "Z[]^_ayz", however, the LED grid displays "Z[\^_
abz". The abz is due to the shift of the table as if a row is missing, but ] exists in the table.
I tried displaying everything in the Alphabet table and for some reason only ] is missing.
Any idea why only ] is missing would be appreciated.
Arduino Uno R3 in case it matters.
/*
Define fonts and show scrolling text
*/
#include <FastLED.h>
#define LED_PIN 7
#define NUM_ROWS 8
#define NUM_COLS 32
#define NUM_LEDS NUM_ROWS * NUM_COLS
#define BRIGHTNESS 2
const byte Alphabet[58][9] PROGMEM = {
{B00000100,B00001010,B00010001,B00010001,B00011111,B00010001,B00010001,B00000000, 5}, // A
{B00011110,B00010001,B00010001,B00011110,B00010001,B00010001,B00011110,B00000000, 5}, // B
{B00001110,B00010001,B00010000,B00010000,B00010000,B00010001,B00001110,B00000000, 5}, // C
{B00011110,B00010001,B00010001,B00010001,B00010001,B00010001,B00011110,B00000000, 5}, // D
{B00011111,B00010000,B00010000,B00011100,B00010000,B00010000,B00011111,B00000000, 5}, // E
{B00011111,B00010000,B00010000,B00011100,B00010000,B00010000,B00010000,B00000000, 5}, // F
{B00001110,B00010001,B00010000,B00010111,B00010001,B00010001,B00001110,B00000000, 5}, // G
{B00010001,B00010001,B00010001,B00011111,B00010001,B00010001,B00010001,B00000000, 5}, // H
{B00011111,B00000100,B00000100,B00000100,B00000100,B00000100,B00011111,B00000000, 5}, // I
{B00001111,B00000001,B00000001,B00000001,B00000001,B00010001,B00001110,B00000000, 5}, // J
{B00010001,B00010010,B00010100,B00011000,B00010100,B00010010,B00010001,B00000000, 5}, // K
{B00010000,B00010000,B00010000,B00010000,B00010000,B00010000,B00011111,B00000000, 5}, // L
{B01000001,B01100011,B01010101,B01001001,B01000001,B01000001,B01000001,B00000000, 7}, // M
{B00010001,B00011001,B00011001,B00010101,B00010011,B00010011,B00010001,B00000000, 5}, // N
{B00001110,B00010001,B00010001,B00010001,B00010001,B00010001,B00001110,B00000000, 5}, // O
{B00011110,B00010001,B00010001,B00011110,B00010000,B00010000,B00010000,B00000000, 5}, // P
{B00001110,B00010001,B00010001,B00010001,B00010101,B00010010,B00001101,B00000000, 5}, // Q
{B00011110,B00010001,B00010001,B00011110,B00010100,B00010010,B00010001,B00000000, 5}, // R
{B00001110,B00010001,B00010000,B00001110,B00000001,B00010001,B00001110,B00000000, 5}, // S
{B00011111,B00000100,B00000100,B00000100,B00000100,B00000100,B00000100,B00000000, 5}, // T
{B00010001,B00010001,B00010001,B00010001,B00010001,B00010001,B00001110,B00000000, 5}, // U
{B00010001,B00010001,B00010001,B00001010,B00001010,B00000100,B00000100,B00000000, 5}, // V
{B01000001,B01000001,B01000001,B01001001,B01010101,B01100011,B01000001,B00000000, 7}, // W
{B00010001,B00010001,B00001010,B00000100,B00001010,B00010001,B00010001,B00000000, 5}, // X
{B00010001,B00010001,B00010001,B00001010,B00000100,B00000100,B00000100,B00000000, 5}, // Y
{B00011111,B00000001,B00000010,B00000100,B00001000,B00010000,B00011111,B00000000, 5}, // Z
{B00000111,B00000100,B00000100,B00000100,B00000100,B00000100,B00000100,B00000111, 3}, // [
{B00010000,B00001000,B00001000,B00000100,B00000100,B00000010,B00000010,B00000001, 5}, // \
{B00000111,B00000001,B00000001,B00000001,B00000001,B00000001,B00000001,B00000111, 3}, // ]
{B00000010,B00000101,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000, 3}, // ^
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001111, 4}, // _
{B00000010,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000, 3}, // `
{B00000000,B00000000,B00000110,B00000001,B00000111,B00001001,B00000111,B00000000, 4}, // a
{B00001000,B00001000,B00001000,B00001110,B00001001,B00001001,B00001110,B00000000, 4}, // b
{B00000000,B00000000,B00000110,B00001001,B00001000,B00001001,B00000110,B00000000, 4}, // c
{B00000001,B00000001,B00000001,B00000111,B00001001,B00001001,B00000111,B00000000, 4}, // d
{B00000000,B00000000,B00000110,B00001001,B00001111,B00001000,B00000110,B00000000, 4}, // e
{B00000110,B00001001,B00001000,B00011110,B00001000,B00001000,B00001000,B00000000, 5}, // f
{B00000000,B00000000,B00000110,B00001001,B00001001,B00000111,B00000001,B00000110, 4}, // g
{B00001000,B00001000,B00001000,B00001110,B00001001,B00001001,B00001001,B00000000, 4}, // h
{B00000000,B00000001,B00000000,B00000001,B00000001,B00000001,B00000001,B00000000, 1}, // i
{B00000000,B00000001,B00000000,B00000001,B00000001,B00000001,B00001001,B00000110, 4}, // j
{B00001000,B00001000,B00001001,B00001010,B00001100,B00001010,B00001001,B00000000, 4}, // k
{B00000001,B00000001,B00000001,B00000001,B00000001,B00000001,B00000001,B00000000, 1}, // l
{B00000000,B00000000,B00011010,B00010101,B00010101,B00010001,B00010001,B00000000, 5}, // m
{B00000000,B00000000,B00001110,B00001001,B00001001,B00001001,B00001001,B00000000, 4}, // n
{B00000000,B00000000,B00000110,B00001001,B00001001,B00001001,B00000110,B00000000, 4}, // o
{B00000000,B00000000,B00000110,B00001001,B00001001,B00001110,B00001000,B00001000, 4}, // p
{B00000000,B00000000,B00000110,B00001001,B00001001,B00000111,B00000001,B00000001, 4}, // q
{B00000000,B00000000,B00000110,B00001001,B00001000,B00001000,B00001000,B00000000, 4}, // r
{B00000000,B00000000,B00000111,B00001000,B00000110,B00000001,B00001110,B00000000, 4}, // s
{B00000000,B00000000,B00000010,B00000111,B00000010,B00000010,B00000011,B00000000, 3}, // t
{B00000000,B00000000,B00001001,B00001001,B00001001,B00001001,B00000111,B00000000, 4}, // u
{B00000000,B00000000,B00010001,B00010001,B00010001,B00001010,B00000100,B00000000, 5}, // v
{B00000000,B00000000,B00010001,B00010001,B00010101,B00010101,B00001010,B00000000, 5}, // w
{B00000000,B00000000,B00010001,B00001010,B00000100,B00001010,B00010001,B00000000, 5}, // x
{B00000000,B00000000,B00001001,B00001001,B00001001,B00000111,B00000001,B00000110, 4}, // y
{B00000000,B00000000,B00001111,B00000001,B00000110,B00001000,B00001111,B00000000, 4} // z
};
CRGB leds[NUM_LEDS];
// String message = "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz";
String message = "Z[\\]^_`ayz";
void setup() {
Serial.begin(9600);
Serial.println("Hello World!");
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
// writeMessage(message, 0, CRGB::White);
for(int position = 0; position < message.length(); position++) {
char letter = message.charAt(position);
Serial.print(letter);
}
Serial.println();
}
void loop() {
int l = message.length() * 8;
for(int i = NUM_COLS; i > -l; i--) {
writeMessage(message, i, CRGB::White);
FastLED.delay(200);
}
}
void writeMessage(String message, int column, CRGB color) {
// black out the board for the message
for(unsigned char r = 0; r < NUM_ROWS; r++) {
for(unsigned char c = 0; c < NUM_COLS; c++) {
leds[ledNum(r, c)] = CRGB::Black;
}
}
for(int position = 0; position < message.length(); position++) {
int letter = message.charAt(position) - 65; // 65 is 'A'
byte width = 0;
if(letter >= 0 && letter < 58) {
width = pgm_read_byte_near(*Alphabet + letter*9 + 8);
for(unsigned char r = 0; r < 8; r++) {
for(unsigned char c = 0; c < width; c++) {
// this loop pulls each bit off the byte one at a time
if((pgm_read_byte_near(*Alphabet + letter*9 + r) >> c & 1) == 1) {
int col = column + width - c - 1; // not sure why this is off by one...
if(col >= 0 && col < NUM_COLS)
leds[ledNum(r, col)] = CRGB::Red;
}
}
}
}
column += width + 1; // move over for next letter (plus a space)
if(column > NUM_COLS)
break; // Too far to the right for any pixel of the next letter to appear
}
FastLED.show();
}
int ledNum(int row, int col) {
if(col % 2 == 1) {
row = NUM_ROWS - row - 1;
}
return col * NUM_ROWS + row;
}