Neopixel ws2812 - 7-segment display

Hello,

i am trying to get this project done but i am getting crazy with it.

My problem is that the LEDs light up but they are not showing numbers. I thing i am doing something wrong with the shifting.

Do somebody sees my error?
Thanks for any help!

#include <Arduino.h>
#include <Arduino.h>
#include <FastLED.h>
#include <WiFi.h>
#include <Wire.h>
#include <RTClib.h>
#include <ESPAsyncWebServer.h>

// DEFINES
// How many LEDs are used in each digit
#define NUM_LEDS_PER_DIGIT 21
// Total number of LEDs in the strip
#define NUM_LEDS 231
// The pin which is connected to the DataIn of the LED strip
#define DATA_PIN 2

//CONSTANTS 
const uint32_t digits[10] = {
  0b00000000000111111111111111111000, // 0
  0b00000000000111000000000000111000, // 1
  0b00000000000000111111000111111111, // 2
  0b00000000000111111000000111111111, // 3
  0b00000000000111000000111000111111, // 4
  0b00000000000111111000111111000111, // 5
  0b00000000000111111111111111000111, // 6
  0b00000000000111000000000111111000, // 7
  0b00000000000111111111111111111111, // 8
  0b00000000000111111000111111111111, // 9
};

const char* ssid = "GS23SP";
const char* password = "gsack2023";


// GLOBALS
CRGB leds[NUM_LEDS];
RTC_DS3231 rtc;
AsyncWebServer server(80);


////////////////////////////////////////////////////
int64_t beginning = 267141400000; //Amount at the time the counter starts
int64_t amount;
int genesis;
////////////////////////////////////////////////////

// FUNCTIONS
void setDigit(int display, int val, CHSV colour) {
  for (int i = 0; i < NUM_LEDS_PER_DIGIT; i++) {
    colour.v = bitRead(digits[val], i) * 255;
    leds[display * NUM_LEDS_PER_DIGIT + i] = colour;
  }
}

void setup() {

  // Initialise a serial connection, used only for debugging
  Serial.begin(115200);
  Serial.println(__FILE__ __DATE__);
  Wire.begin();
  // Initialize the RTC
  rtc.begin();
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

  // Start the WiFi access point
  WiFi.softAP(ssid, password);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);

  // Serve the time setting page at the root path
  server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    String html = "<html><body>";
    html += "<h1>Set Time</h1>";
    html += "<form method='get' action='/settime'>";
    html += "Year: <input type='text' name='year'><br>";
    html += "Month: <input type='text' name='month'><br>";
    html += "Day: <input type='text' name='day'><br>";
    html += "Hour: <input type='text' name='hour'><br>";
    html += "Minute: <input type='text' name='minute'><br>";
    html += "<input type='submit' value='Set Time'>";
    html += "</form>";
    html += "</body></html>";
    request->send(200, "text/html", html);
  });

  // Handle requests to set the time
  server.on("/settime", HTTP_GET, [](AsyncWebServerRequest * request) {
    int year = request->arg("year").toInt();
    int month = request->arg("month").toInt();
    int day = request->arg("day").toInt();
    int hour = request->arg("hour").toInt();
    int minute = request->arg("minute").toInt();

    // Set the time on the RTC
    DateTime newTime = DateTime(year, month, day, hour, minute);
    rtc.adjust(newTime);

    request->send(200, "text/html", "<h1>Time set successfully</h1>");
  });
  // Start the server
  server.begin();
  Serial.println("Server started");
  // Initialise the LED strip
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
}


void loop() {
  DateTime now = rtc.now();
  genesis = (now.unixtime() * 160); //Amount at the time the time starts-1970
  amount = ((genesis - beginning) + 74152676000 - 576000);
  amount %= 100000000000; //Reset x after 99999999999

  setDigit(0, amount / 10000000000, CHSV(255, 255, 255));
  setDigit(1,(amount / 1000000000) % 10, CHSV(255, 255, 255));
  setDigit(2,(amount / 100000000) % 10, CHSV(255, 255, 255));
  setDigit(3,(amount / 10000000) % 10, CHSV(255, 255, 255));
  setDigit(4,(amount / 1000000) % 10, CHSV(255, 255, 255));
  setDigit(5,(amount / 100000) % 10, CHSV(255, 255, 255));
  setDigit(6,(amount / 10000) % 10, CHSV(255, 255, 255));
  setDigit(7,(amount / 1000) % 10, CHSV(255, 255, 255));
  setDigit(8,(amount / 100) % 10, CHSV(255, 255, 255));
  setDigit(9,(amount / 10) % 10, CHSV(255, 255, 255));
  setDigit(10,(amount / 1) % 10, CHSV(255, 255, 255));

 
  FastLED.show();
  //Serial.println(amount);
 }

Not showing numbers... but do the sections light?

You have 231 neopixels divided by 21 pix/section equals 11 sections... your "digits[]" are 10 of those 11. Is the ":" the eleventh?

The digits are working fine. If i write simple numbers in the setDigit function everything works just fine.

I think that I have an error in the separation of every single digit of the amount variable using the modulo operation.

Here is my working example without the conversion with modulo:

#include <Arduino.h>
#include <Arduino.h>
#include <FastLED.h>
#include <WiFi.h>
#include <Wire.h>
#include <RTClib.h>
#include <ESPAsyncWebServer.h>

// DEFINES
// How many LEDs are used in each digit
#define NUM_LEDS_PER_DIGIT 21
// Total number of LEDs in the strip
#define NUM_LEDS 231
// The pin which is connected to the DataIn of the LED strip
#define DATA_PIN 2



//CONSTANTS 
const uint32_t digits[10] = {
          
/*
            aaa
          f    b
          f    b
          f    b
           ggg
          e    c
          e    c
          e    c
           ddd
*/             

//0b00000000000cccdddeeefffaaabbbggg
  0b00000000000111111111111111111000, // 0
  0b00000000000111000000000000111000, // 1
  0b00000000000000111111000111111111, // 2
  0b00000000000111111000000111111111, // 3
  0b00000000000111000000111000111111, // 4
  0b00000000000111111000111111000111, // 5
  0b00000000000111111111111000000111, // 6
  0b00000000000111000000000111111000, // 7
  0b00000000000111111111111111111111, // 8
  0b00000000000111000000111111111111, // 9
//0b00000000000cccdddeeefffaaabbbggg  
};

const char* ssid = "GS23SP";
const char* password = "gsack2023";


// GLOBALS
CRGB leds[NUM_LEDS];
RTC_DS3231 rtc;
AsyncWebServer server(80);


////////////////////////////////////////////////////
int64_t beginning = 267141400000; //Amount at the time the counter starts
int64_t amount;
int genesis;
////////////////////////////////////////////////////

// FUNCTIONS
void setDigit(int display, int val, CHSV colour) {
  for (int i = 0; i < NUM_LEDS_PER_DIGIT; i++) {
    colour.v = bitRead(digits[val], i) * 255;
    leds[display * NUM_LEDS_PER_DIGIT + i] = colour;
  }
}

void setup() {

  // Initialise a serial connection, used only for debugging
  Serial.begin(115200);
  Serial.println(__FILE__ __DATE__);
  Wire.begin();
  // Initialize the RTC
  rtc.begin();
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

  // Start the WiFi access point
  WiFi.softAP(ssid, password);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);

  // Serve the time setting page at the root path
  server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    String html = "<html><body>";
    html += "<h1>Set Time</h1>";
    html += "<form method='get' action='/settime'>";
    html += "Year: <input type='text' name='year'><br>";
    html += "Month: <input type='text' name='month'><br>";
    html += "Day: <input type='text' name='day'><br>";
    html += "Hour: <input type='text' name='hour'><br>";
    html += "Minute: <input type='text' name='minute'><br>";
    html += "<input type='submit' value='Set Time'>";
    html += "</form>";
    html += "</body></html>";
    request->send(200, "text/html", html);
  });

  // Handle requests to set the time
  server.on("/settime", HTTP_GET, [](AsyncWebServerRequest * request) {
    int year = request->arg("year").toInt();
    int month = request->arg("month").toInt();
    int day = request->arg("day").toInt();
    int hour = request->arg("hour").toInt();
    int minute = request->arg("minute").toInt();

    // Set the time on the RTC
    DateTime newTime = DateTime(year, month, day, hour, minute);
    rtc.adjust(newTime);

    request->send(200, "text/html", "<h1>Time set successfully</h1>");
  });
  // Start the server
  server.begin();
  Serial.println("Server started");
  // Initialise the LED strip
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
}


void loop() {
  DateTime now = rtc.now();
  genesis = (now.unixtime() * 160); //Amount at the time the time starts-1970
  amount = ((genesis - beginning) + 74152676000 - 576000);
  amount %= 100000000000; //Reset x after 99999999999

  setDigit(0, 1, CHSV(255, 255, 255));
  setDigit(1, 2, CHSV(255, 255, 255));
  setDigit(2, 3, CHSV(255, 255, 255));
  setDigit(3, 4, CHSV(255, 255, 255));
  setDigit(4, 5, CHSV(255, 255, 255));
  setDigit(5, 6, CHSV(255, 255, 255));
  setDigit(6, 7, CHSV(255, 255, 255));
  setDigit(7, 8, CHSV(255, 255, 255));
  setDigit(8, 9, CHSV(255, 255, 255));
  setDigit(9, 0, CHSV(255, 255, 255));
  setDigit(10,8, CHSV(255, 255, 255));

}

 
  FastLED.show();
  //Serial.println(amount);
 }

What is character #11? Is this clock display, "00:00"?
If one character works, will two work?

Have you tried printing amount to serial monitor to check the value is as expected?

Try changing

  setDigit(0, amount / 10000000000, CHSV(255, 255, 255));
  setDigit(1,(amount / 1000000000) % 10, CHSV(255, 255, 255));
  setDigit(2,(amount / 100000000) % 10, CHSV(255, 255, 255));
  setDigit(3,(amount / 10000000) % 10, CHSV(255, 255, 255));
  setDigit(4,(amount / 1000000) % 10, CHSV(255, 255, 255));
  setDigit(5,(amount / 100000) % 10, CHSV(255, 255, 255));
  setDigit(6,(amount / 10000) % 10, CHSV(255, 255, 255));
  setDigit(7,(amount / 1000) % 10, CHSV(255, 255, 255));
  setDigit(8,(amount / 100) % 10, CHSV(255, 255, 255));
  setDigit(9,(amount / 10) % 10, CHSV(255, 255, 255));
  setDigit(10,(amount / 1) % 10, CHSV(255, 255, 255));

to

  for(int d=10; d>0; d--) {
    setDigit(d, amount % 10, CHSV(255, 255, 255));
    amount /= 10;
    }
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.