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 (0–999) 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 (0–9). 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