These are chat archives for Makuna/NeoPixelBus

26th
Dec 2016
pippin88
@pippin88
Dec 26 2016 12:35

Michael, thanks very much for the response. Those snippets have taught me a huge amount! I'm working on it. I have no background programming, so every time I do something, I have to learn and relearn the very basics. Thank you for your help and library.
From my understanding of your response:
const WordLocation WordLocations[Word_COUNT] = is an array of arrays, which contains the actual pixel data of the words.
I define an index of the words (the enum) which means, for instance, NEAR will = 0, EXACTLY will = 2 (see below). I can then use this index, and the struct to retrieve data from the array easily.
The struct (WordLocation) makes it easier to store and access the data.

The below code (snippet) successfully outputs '4', being the number of pixels in word NEAR

``````struct wordLocation { //define a data structure. Every wordLocation object will have .row, .firstCol, .numLetters
uint8_t row;
uint8_t firstCol;
uint8_t numLetters;
};

//ENUM acts as index for array. Using NEAR in code, will get replaced by 0
enum Word {
NEAR, //0
PAST1, //1
EXACTLY, //2 etc
A1,
QUARTER,
TWENTY,
MTEN,
A2,
MFIVE,
I,
HALF,
TO,
PAST2,
Word_COUNT // the last one will represent how many words total
};

Word Word; // <-- the actual instance

const wordLocation wordLocations[Word_COUNT] = {
{0, 0, 4}, //NEAR
{0, 4, 4}, //past1
{0, 8, 7}, //exactly
{0, 15, 1}, //a1
{1, 0, 7}, //quarter
{1, 7, 6}, //twenty
{1, 13, 3}, //mten
{2, 0, 1}, //a2
{2, 1, 4}, //mfive
{2, 5, 1}, //i
{2, 6, 4}, //half
{2, 10, 2}, //to
{2, 12, 4} //past2
};

wordLocation wordLocation;

void setup() {
Serial.begin(57600);  //Begin serial communcation

Serial.print("wordLocations[NEAR].numLetters: ");
Serial.println(wordLocations[NEAR].numLetters);``````
Michael Miller
@Makuna
Dec 26 2016 19:49

@pippin88 General feedback first...
1) When working with ENUMs, the values inside are not unique, so you should preface them with the enum name and then underscore (Word_Near not just NEAR). Also, it is generally accepted to use case mixed, it makes it easier to read. All caps is generally reserved for DEFINE values. The last entry, Word_COUNT, has the count all caps to make it clear that it is the count of entries in the enum and not an actual enum entry. Sometimes you will something like this also...

``````enum Word {
Word_FIRST,
Word_Near = Word_FIRST,  // resets the auto counter to zero
blah, blah, blah
}``````

This gives you a variable that is the first without really caring what the word order is. Doing something similar can also allow you start your enum numerical values not at zero or even skip some if you don't need them.
2) Try to keep the types different from the variables. Word and Word. This is easy if you follow the guideline of all variables start lower case and all types start with upper case. So it would be `Word` for the type, and `word` for the variable. `WordLocation` for the type, and `wordLocation` for the variable.

Michael Miller
@Makuna
Dec 26 2016 19:54