How to Make and Control Pixel LED Seven Segment Digit Using Arduino by Manmohan Pal

How to Make and Control Pixel LED Seven Segment Digit Using Arduino by Manmohan Pal



Controlling a WS2812 (NeoPixel) seven-segment display using Arduino involves:

1.      Defining which LEDs belong to each segment

2.      Creating digit-to-segment mappings

3.      Using a library like Adafruit NeoPixel or FastLED

4.      Writing code to display numbers by lighting the correct segments


🔌 Wiring Setup

·         Data IN of WS2812 segment → Arduino pin (e.g., D6)

·         VCC → 5V (use external supply for many LEDs)

·         GND → Common ground with Arduino



 






Step-by-Step Arduino Code (Basic Version)

📦 Requirements

Install Adafruit NeoPixel library in Arduino IDE:

Sketch → Include Library → Manage Libraries → Search "Adafruit NeoPixel" → Install



#include <Adafruit_NeoPixel.h>

#define PIN 6            // Data pin for WS2812
#define NUMPIXELS 21     // Total number of LEDs
#define BRIGHTNESS 50

Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

// Each segment has 3 LEDs (you can change this)
const int ledsPerSegment = 3;

// Map segments: a, b, c, d, e, f, g (segment ID to LED index)
int segmentMap[7][3] = {
  {0, 1, 2},    // a
  {3, 4, 5},    // b
  {6, 7, 8},    // c
  {9,10,11},    // d
  {12,13,14},   // e
  {15,16,17},   // f
  {18,19,20}    // g
};

// Digit to segment ON/OFF map (a-g)
const bool digitSegments[10][7] = {
  {1,1,1,1,1,1,0},  // 0
  {0,1,1,0,0,0,0},  // 1
  {1,1,0,1,1,0,1},  // 2
  {1,1,1,1,0,0,1},  // 3
  {0,1,1,0,0,1,1},  // 4
  {1,0,1,1,0,1,1},  // 5
  {1,0,1,1,1,1,1},  // 6
  {1,1,1,0,0,0,0},  // 7
  {1,1,1,1,1,1,1},  // 8
  {1,1,1,1,0,1,1}   // 9
};

void setup() {
  strip.begin();
  strip.setBrightness(BRIGHTNESS);
  strip.show();
}

void loop() {
  for (int i = 0; i < 10; i++) {
    displayDigit(i, strip.Color(255, 0, 0));  // Red digits
    delay(1000);
  }
}

void displayDigit(int digit, uint32_t color) {
  strip.clear();
 
  for (int seg = 0; seg < 7; seg++) {
    if (digitSegments[digit][seg]) {
      for (int j = 0; j < ledsPerSegment; j++) {
        strip.setPixelColor(segmentMap[seg][j], color);
      }
    }
  }

  strip.show();
}




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...