Thank you for you replies @ruilviana and @noiasca
Full code posted below:
#define DISPLAY_WIDTH 26
#define DISPLAY_HEIGHT 7
#define NUM_LEDS (DISPLAY_WIDTH*DISPLAY_HEIGHT)
#define DISPLAY_PIN 2
#ifndef CLOCK_DISPLAY
#define CLOCK_DISPLAY
// font from https://github.com/idispatch/raster-fonts/blob/master/font-6x8.c#L598
const uint8_t NUMBER_FONT[][DISPLAY_HEIGHT] = {
{
0x38, /* 001110 */
0x44, /* 010001 */
0x4C, /* 010011 */
0x54, /* 010101 */
0x64, /* 011001 */
0x44, /* 010001 */
0x38, /* 001110 */
},
{
0x10, /* 000100 */
0x30, /* 001100 */
0x10, /* 000100 */
0x10, /* 000100 */
0x10, /* 000100 */
0x10, /* 000100 */
0x10, /* 000100 */
},
{
0x38, /* 001110 */
0x44, /* 010001 */
0x04, /* 000001 */
0x18, /* 000110 */
0x20, /* 001000 */
0x40, /* 010000 */
0x7C, /* 011111 */
},
{
0x38, /* 001110 */
0x44, /* 010001 */
0x04, /* 000001 */
0x38, /* 001110 */
0x04, /* 000001 */
0x44, /* 010001 */
0x38, /* 001110 */
},
{
0x08, /* 000010 */
0x18, /* 000110 */
0x28, /* 001010 */
0x48, /* 010010 */
0x7C, /* 011111 */
0x08, /* 000010 */
0x08, /* 000010 */
},
{
0x7C, /* 011111 */
0x40, /* 010000 */
0x40, /* 010000 */
0x78, /* 011110 */
0x04, /* 000001 */
0x44, /* 010001 */
0x38, /* 001110 */
},
{
0x18, /* 000110 */
0x20, /* 001000 */
0x40, /* 010000 */
0x78, /* 011110 */
0x44, /* 010001 */
0x44, /* 010001 */
0x38, /* 001110 */
},
{
0x7C, /* 011111 */
0x04, /* 000001 */
0x08, /* 000010 */
0x10, /* 000100 */
0x20, /* 001000 */
0x20, /* 001000 */
0x20, /* 001000 */
},
{
0x38, /* 001110 */
0x44, /* 010001 */
0x44, /* 010001 */
0x38, /* 001110 */
0x44, /* 010001 */
0x44, /* 010001 */
0x38, /* 001110 */
},
{
0x38, /* 001110 */
0x44, /* 010001 */
0x44, /* 010001 */
0x3C, /* 001111 */
0x04, /* 000001 */
0x08, /* 000010 */
0x30, /* 001100 */
}
};
uint8_t COLON[] = {
0b000,
0b011,
0b011,
0b000,
0b011,
0b011,
0b000
};
#endif
void initDisplay(void);
void displayTime(uint8_t hours, uint8_t minutes, uint8_t seconds);
#include <FastLED.h>
#include <stdint.h>
#include "clock_display.h"
#define FONT_WIDTH 6
#define FONT_MASK 0x80
CRGB leds[NUM_LEDS];
bool stateOn = false;
void initDisplay(void) {
pinMode(DISPLAY_PIN, OUTPUT);
delay( 3000 ); // power-up safety delay
FastLED.addLeds<WS2812, DISPLAY_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(1);
FastLED.clear();
}
int getLEDpos(int x, int y){ // for a serpentine raster
int pos;
if(y & 0x1) { // is y odd
pos = y * DISPLAY_WIDTH + (DISPLAY_WIDTH -1 - x) ;
} else { // y is even
pos = y * DISPLAY_WIDTH + x;
}
return pos;
}
void displayDigit(uint8_t digit, uint8_t xOffset, uint8_t yOffset) {
for (uint8_t x = 0; x < FONT_WIDTH; x++) {
for (uint8_t y = 0; y < DISPLAY_HEIGHT; y++) {
uint8_t on = (NUMBER_FONT[digit][y] & (FONT_MASK >> x)) > 0;
leds[getLEDpos(x + xOffset, y + yOffset)] = on*CRGB::Lime + CRGB::Black;
}
}
}
void loop() {
if(stateOn)
{
leds[65] = CRGB::Red;
leds[117] = CRGB::Red;
FastLED.show();
delay(1000);
stateOn = false;
}
else
{
leds[65] = CRGB::Black;
leds[117] = CRGB::Black;
FastLED.show();
delay(1000);
stateOn = true;
}
time(¤tTime);
// convert UTC UNIX timestamp to timeinfo in local timezone
localtime_r(¤tTime, &timeinfo);
displayTime(timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
}
void displayTime(uint8_t hours, uint8_t minutes, uint8_t seconds) {
FastLED.clear();
displayDigit(hours/10,0, 0);
displayDigit(hours%10, FONT_WIDTH, 0);
displayDigit(minutes/10, FONT_WIDTH*2+2 , 0);
displayDigit(minutes%10, FONT_WIDTH*3+2 , 0);
FastLED.show();
}