Pixel LED 3 Digit Seven Segment token number Display board

 Pixel LED 3 Digit  Seven Segment token  number Display board






This code is for a 3-digit 7-segment display made using WS2812 (NeoPixel) LEDs, controlled by a NodeMCU ESP8266. It creates a Wi-Fi hotspot and a web page that lets the user input a number (0999) and change the color of the digits using RGB sliders. The selected number is then shown on the LED display.

๐Ÿ”ง Libraries

#include <ESP8266WiFi.h>         // For Wi-Fi functionality
#include <ESP8266WebServer.h>    // For serving a web page
#include <Adafruit_NeoPixel.h>   // For controlling WS2812 LEDs

๐Ÿ”ฉ Configuration

#define LED_PIN    D6                // Data pin connected to WS2812 LEDs
#define NUM_DIGITS 3                 // 3-digit display
#define LEDS_PER_SEGMENT 4           // Each segment has 4 LEDs
#define SEGMENTS_PER_DIGIT 7         // 7 segments in a digit
#define TOTAL_LEDS (NUM_DIGITS * SEGMENTS_PER_DIGIT * LEDS_PER_SEGMENT)

๐Ÿ’ก NeoPixel Setup

Adafruit_NeoPixel strip(TOTAL_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);

Initializes the total number of LEDs and the data format.
๐Ÿ”  Digit to Segment Mapping

const byte digitMap[10][7] = { ... }

Each row represents a digit (09). Each column (7 total) represents a segment: F, A, B, C, D, E, G. A value of 1 means the segment is ON for that digit.
๐ŸŒ Web Server & Variables

ESP8266WebServer server(80);
int displayNumber = 0;
uint32_t currentColor = strip.Color(255, 0, 0);  // Default red

๐Ÿ› ️ setup() Function

    Start Serial and NeoPixel
    Start Wi-Fi in Access Point Mode

WiFi.softAP("TokenDisplay", "12345678");

Starts a Wi-Fi hotspot named TokenDisplay with password 12345678.

Setup Web Routes

    server.on("/", handleForm);         // Display HTML form
    server.on("/submit", handleSubmit); // Handle form submission

๐Ÿ” loop() Function

    Handles incoming web clients.

    Updates display only if:

        Number or color has changed.

if (displayNumber != previousNumber || currentColor != previousColor)

๐ŸŒ handleForm() – HTML Page

    Displays:

        Input box for token number

        RGB sliders

        Live color preview (<div id="colorPreview">)

    JavaScript updates the preview color in real time.

๐Ÿ“ฅ handleSubmit() – Form Submission Handler

    Reads the form inputs:

        number, r, g, b

    Converts them to an integer and color

    Updates displayNumber and currentColor

    Redirects back to the form (server.sendHeader("Location", "/", true))

๐Ÿ”ข showNumber(int num)

    Converts number to individual digits (e.g., 456 → [4, 5, 6])

    For each digit:

        Uses digitMap to light up the correct segments

        For each segment:

            Lights all LEDs in that segment with currentColor

    Displays it using strip.show()

๐Ÿ“Š LED Addressing Logic

Each LED is addressed as:

int startLED = (digitIndex * SEGMENTS_PER_DIGIT + segmentIndex) * LEDS_PER_SEGMENT;

This ensures LEDs for all segments and digits are lit properly.
✅ Summary
Feature Description
Wi-Fi Hotspot NodeMCU acts as access point
Web Interface Allows number and color input
3-Digit Display Shows values from 000 to 999
NeoPixel Control  Colors and brightness managed with Adafruit_NeoPixel
Live Color Preview  JavaScript updates preview as sliders move

No comments:

Post a Comment

Wifi Home automation Diy kit

 Wifi Home automation Diy kit By Manmohan Pal Wifi Home Automation Kit Hi, This is Manmohan Pal, I am glad to present a DIY kit for Home Aut...