Paul...thanks for the advice...I'm not experienced enough to know what you mean about the memory waste...should I change the assignment of my pixelarray from an int to "byte" values?
As to advantages of an array...yes...as soon as I started lookign at coding it I figured out there IS an advantage.
As what I wanted was a "smooth" scroll - ie, the whole word, not letter by letter, for me the simplest (not necessarily best) way was to put the whole word in a 2D array. Then I realised that my 6x6 pixel array was really just a moving "window" along the array that contains the word.
In short...this works...it may not be memory efficient, pretty or clever...but it works!
//Scrolling letters
#include <Adafruit_NeoPixel.h>
#define N_LEDS 36 //LEDS in strip
#define PIN 8 //output pin 1
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
int p;
Serial.begin(9600);
randomSeed(analogRead(0));
strip.setBrightness(50);
strip.begin();
// Test pixels
strip.setPixelColor (0, 0, 50, 0);
strip.setPixelColor (5, 0, 50, 0);
strip.setPixelColor (30, 0, 50, 0);
strip.setPixelColor (35, 0, 50, 0);
strip.show();
delay(200);
// clear all pixels
for (p = 0; p <= (N_LEDS - 1); p++) {
strip.setPixelColor(p, 0, 0, 0);
}
strip.show();
}
void loop() {
//(0,0) bottom left, (max,max) top right
int pixelarray[6][6] = {
{ 5, 6, 17, 18, 29, 30, },
{ 4, 7, 16, 19, 28, 31, },
{ 3, 8, 15, 20, 27, 32, },
{ 2, 9, 14, 21, 26, 33, },
{ 1, 10, 13, 22, 25, 34, },
{ 0, 11, 12, 23, 24, 35, },
};
int arraysize = 0;
int lightpitch = 1;
int RVa = 255;
int GVa = 255;
int BVa = 255;
int p; //pixel number
int x;
int y;
int i;
int n;
int KING[6][20] = {
{1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0,},
{1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1,},
{1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0,},
{1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1,},
{1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1,},
{1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0,},
};
int HERO[6][19] = {
{1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0,},
{1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1,},
{1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1,},
{1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1,},
{1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1,},
{1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0,},
};
//scroll "King"
arraysize = sizeof(KING[0]) / sizeof(int);
Serial.print("KING contains ");
Serial.print(arraysize);
Serial.println(" elements");
for (i = 0; i <= arraysize - 6; i++) {
for (x = 0; x <= 5; x++) {
for (y = 5; y >= 0; y--) {
strip.setPixelColor(pixelarray[x][y], RVa * KING[5 - y][i + x], 0, 0);
}
}
strip.show();
delay(500);
}
}