Understanding the RGB coding in this program

Hi all!

I came across this project on reddit :

And i wanted to go ahead and try to make myself one like it.

I have basic knowlege about <Adafruit_NeoPixel.h> and <Adafruit_NeoMatrix.h>
but in this code he seems to use some sort of “masking” to define what leds to controll at which time.

I’ve spendt several evenings to try and wrap my head around how it works, but I just can’t find an answere.

Since I’m Norwegian the clock format doesn’t fit the Norwegian format, and because of that I need to change what leds to turn on and when to turn them on.

My question is: How and where do i change what leds to control using this type of coding?

(Btw his example is 11x11 grid and I’m using a 10lenght x 11with, if that matters)

Sorry for the long post, I tried to post the code below, but it exceeds the maximum allowed lenght.

You can find the code here:

https://github.com/grahamvinyl/WordClock_color_edit/blob/master/WordClock_color_edit.ino

You can find the code here:

That is NOT the code you are compiling/struggling with.

If you want help on github, why are you here?

If you want help here, why is your code not HERE?

I tried to post the code from github in my post but as i stated in my OP it exceeded the maximum allowed lenght on one post, hence why i have linked to github.

I am here to get some help/pointers on how i should convert that program and make it so that i can apply it to my Norwegian clock format.

I have posted the first part of the program below. I’ll try to explain what I want help with again in a better way:

Lets say i want to redifine the LEDs from showing “ITS” (3leds active) to “KLOKKEN ER” (9leds active)
how to i go forth and make that statement. From what i can tell it has something do do with

#define phraseITS mask[0] |= 0xE000

Being the novice I am, this does not make too much sense to me. Maybe you have some pointers for me.

I hope this makes it more clear to you.

thanks

#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#include <Wire.h>         //http://arduino.cc/en/Reference/Wire (included with Arduino IDE)
#include "RTClib.h"
#define PIN 6

//IF CLOCK TIME IS WRONG: RUN FILE->EXAMPLE->DS1307RTC->SET TIME

RTC_DS3231 rtc;

// matrix of 11 - 16 bit ints (shorts) for displaying the leds
uint16_t mask[11];

/* notes for my arduino wiring:
 * pin 2: top button (set)
 * pin 3: middle button (up)
 * pin 4: bottom button (down)
 * pin 6: LED strand data
 * pin A0: photosensor
 * pin A4: RTC Module SDA
 * pin A5: RTC Module SCL
 */

  int buttonSet=2;
  int buttonUp=3;
  int buttonDown=4;
  int photoResistor=A0;
  int photoRead;
  int dimmer=1;

  //////////////////////////////////SET COLORS/////////////////////////////

  //WORDCLOCK COLORS
  int wordred   = 80;
  int wordblue  = 255;
  int wordgreen = 160;

  //DIGIT COLORS (HOURS)
  int hourred   = 130;
  int hourblue  = 130;
  int hourgreen = 130;
  //DIGIT COLORS (MINUTES)
  int minred    = 250;
  int minblue   = 250;
  int mingreen  = 250;

  //DATE COLORS (MONTH)
  int monthred   = 125;
  int monthblue  = 25;
  int monthgreen = 50;
  //DATE COLORS (DAY)
  int dayred    = 250;
  int dayblue   = 50;
  int daygreen  = 100;

  //DIMABLE (once photoresistor is programmed)
  int dimred=wordred/dimmer;
  int dimblue=wordblue/dimmer;
  int dimgreen=wordgreen/dimmer;
  
//////////////////////////////////////////////////////////////////////////////

  int mytimemonth;
  int mytimeday;
  int mytimehr;
  int mytimemin;
  int mytimesec;
  
  int j; //an integer for the color shifting effect

  int mode = 0;
  int lastState = LOW;   // the previous reading from the input pin
  int buttonState;
  // the following variables are long's because the time, measured in miliseconds,
  // will quickly become a bigger number than can be stored in an int.
  long lastDebounceTime = 0;  // the last time the output pin was toggled
  long debounceDelay = 50;    // the debounce time; increase if the output flickers
  
#define WORD_MODE 0
#define DIGIT_MODE 1
#define DATE_MODE 2
#define BDAY_MODE 3
#define MAX_MODE 4

#define phraseITS        mask[0]  |= 0xE000
#define phraseA          mask[0]  |= 0x800
#define phraseFIVE       mask[2]  |= 0x1E0
#define phraseTEN        mask[1]  |= 0x7000
#define phraseQUARTER    mask[1]  |= 0xFE0
#define phraseTWENTY     mask[2]  |= 0xFC00
#define phraseHALF       mask[0]  |= 0x3C0
#define phrasePAST       mask[3]  |= 0x3C0
#define phraseTIL        mask[3]  |= 0x1C00
#define hourONE          mask[9]  |= 0xE000
#define hourTWO          mask[7]  |= 0xE0
#define hourTHREE        mask[9]  |= 0x3E0
#define hourFOUR         mask[10] |= 0xF000
#define hourFIVE         mask[7]  |= 0xF000
#define hourSIX          mask[9]  |= 0x1C00
#define hourSEVEN        mask[4]  |= 0x7C00
#define hourEIGHT        mask[8]  |= 0x3E0
#define hourNINE         mask[7]  |= 0xF00
#define hourTEN          mask[6]  |= 0xE0
#define hourELEVEN       mask[8]  |= 0xFC00
#define hourNOON         mask[4]  |= 0x1E0
#define hourMIDNIGHT     mask[6]  |= 0xFF00
#define phraseOCLOCK     mask[10] |= 0x7E0
#define phraseHAPPY      mask[0]  |= 0x200, mask[1]  |= 0x200, mask[2]  |= 0x200, mask[3]  |= 0x200, mask[4]  |= 0x200
#define phraseBIRTHDAY   mask[5]  |= 0x7DC0

typedef uint8_t Character[7];
const Character charmap[] = {
  {
    0b01110,
    0b10001,
    0b10001,
    0b10001,
    0b10001,
    0b10001,
    0b01110
  },
  {
    0b00100,
    0b01100,
    0b00100,
    0b00100,
    0b00100,
    0b00100,
    0b01110
  },
  {
    0b01110,
    0b10001,
    0b00001,
    0b00010,
    0b00100,
    0b01000,
    0b11111
  },
  {
    0b11111,
    0b00010,
    0b00100,
    0b00010,
    0b00001,
    0b10001,
    0b01110
  },
  {
    0b00010,
    0b00110,
    0b01010,
    0b10010,
    0b11111,
    0b00010,
    0b00010
  },
  {
    0b11111,
    0b10000,
    0b11110,
    0b00001,
    0b00001,
    0b10001,
    0b01110
  },
  {
    0b00110,
    0b01000,
    0b10000,
    0b11110,
    0b10001,
    0b10001,
    0b01110
  },
  {
    0b11111,
    0b00001,
    0b00010,
    0b00100,
    0b01000,
    0b01000,
    0b01000
  },
  {
    0b01110,
    0b10001,
    0b10001,
    0b01110,
    0b10001,
    0b10001,
    0b01110
  },
  {
    0b01110,
    0b10001,
    0b10001,
    0b01111,
    0b00001,
    0b00010,
    0b01100
  }
};

// define pins
#define NEOPIN 6

If you had read the stickies at the top of the forum, they show how to get around the 9500 character limit.

Without seeing where the mask array gets assigned values, it is hard to see what the masking is accomplishing.

Dert: Lets say i want to redifine the LEDs from showing "ITS" (3 leds active) to "KLOKKEN ER" (9 leds active) how to i go forth and make that statement. From what i can tell it has something do do with#define phraseITS        mask[0]  |= 0xE000

Assuming that "KLOKKEN ER" are the first 10 characters in the first line of the array of characters you would write something like:#define phraseKLOKKEN_ER  mask[0] |= 0xFEC0;

johnwasser: Assuming that "KLOKKEN ER" are the first 10 characters in the first line of the array of characters you would write something like:#define phraseKLOKKEN_ER  mask[0] |= 0xFEC0;

Great! Thank you :)

How did you end up with "mask[0] |= 0xFEC0;" ?

is the a table or something that you refer to, do you perhaps want to explain it? Or you could link me a site that explains it?

0xF = 0b1111 0xE = 0b1110 0xC = 0b1100 0x0 = 0b0000

Together that is 0b11111110110000 : seven LEDs on for "KLOKKEN", 1 LED off for the space, two LEDs on for "ER". It's mask[0] because it is the top row.

johnwasser: 0xF = 0b1111 0xE = 0b1110 0xC = 0b1100 0x0 = 0b0000

Together that is 0b11111110110000 : seven LEDs on for "KLOKKEN", 1 LED off for the space, two LEDs on for "ER". It's mask[0] because it is the top row.

Thank you very much! The pieces are now coming together. I still need to translate the rest of the words, but i think i can do that by myself.

How do you know that:

0xF = 0b1111 0xE = 0b1110 0xC = 0b1100 0x0 = 0b0000

if i want other combinations, where can i find those?

This little program converts numbers entered via serial from and to dec, hex, oct or bin.

void setup() {
  Serial.begin(250000);
}

void loop() {
  static char commandbuffer[20];
  static int i = 0;
  if (Serial.available()) {
    char c = Serial.read();
    commandbuffer[i] = c;
    if (c == 10) {
      commandbuffer[i] = 0;
      long value;
      if (!strncmp_P(commandbuffer, PSTR("0b"), 2)) {
        value = strtol(commandbuffer + 2, NULL, 2);
      } else {
        value = strtol(commandbuffer, NULL, 0);
      }
      Serial.print(commandbuffer);
      Serial.print(F(" -> "));
      Serial.print(value);
      Serial.print(F(" (dec), 0x"));
      Serial.print(value, HEX);
      Serial.print(F(" (hex), 0"));
      Serial.print(value, OCT);
      Serial.print(F(" (oct), 0b"));
      Serial.print(value, BIN);
      Serial.println(F(" (bin)"));
      i = 0;
    } else if (c == 13) { // cr ignorieren
    } else if (++i == sizeof(commandbuffer)) {
      i--;
    }
  }
}
123 -> 123 (dec), 0x7B (hex), 0173 (oct), 0b1111011 (bin)
077 -> 63 (dec), 0x3F (hex), 077 (oct), 0b111111 (bin)
0xF -> 15 (dec), 0xF (hex), 017 (oct), 0b1111 (bin)
0b111 -> 7 (dec), 0x7 (hex), 07 (oct), 0b111 (bin)

Whandall: This little program converts numbers entered via serial from and to dec, hex, oct or bin.

void setup() {
  Serial.begin(250000);
}

void loop() {   static char commandbuffer[20];   static int i = 0;   if (Serial.available()) {     char c = Serial.read();     commandbuffer[i] = c;     if (c == 10) {       commandbuffer[i] = 0;       long value;       if (!strncmp_P(commandbuffer, PSTR("0b"), 2)) {         value = strtol(commandbuffer + 2, NULL, 2);       } else {         value = strtol(commandbuffer, NULL, 0);       }       Serial.print(commandbuffer);       Serial.print(F(" -> "));       Serial.print(value);       Serial.print(F(" (dec), 0x"));       Serial.print(value, HEX);       Serial.print(F(" (hex), 0"));       Serial.print(value, OCT);       Serial.print(F(" (oct), 0b"));       Serial.print(value, BIN);       Serial.println(F(" (bin)"));       i = 0;     } else if (c == 13) { // cr ignorieren     } else if (++i == sizeof(commandbuffer)) {       i--;     }   } }




123 -> 123 (dec), 0x7B (hex), 0173 (oct), 0b1111011 (bin) 077 -> 63 (dec), 0x3F (hex), 077 (oct), 0b111111 (bin) 0xF -> 15 (dec), 0xF (hex), 017 (oct), 0b1111 (bin) 0b111 -> 7 (dec), 0x7 (hex), 07 (oct), 0b111 (bin) ```

Thanks for your reply. I tried to play around with this program and to send some values in the serial monitor. I must be doing something wrong because it won't convert for me.

What i did was go into serial monitor, 250000 baud and then i tried to send some random values.

I apologize for being so green at this area, again thank you for sparing some time to help me

Line ending NL and CR?

How do you know that:

0b1000 = 8 0b0100 = 4 0b0010 = 2 0b0001 = 1


0b1111 = 15 = 0x0F

That did it! Much appreciated :) I am going to bed now and will continue with this when i get home from work tomorrow.

Thank you all for your help, I've learned many new things today :)