NeoPixel Digit Layout
Run the NeoPixel Digit Layout MicroSim Fullscreen
Edit in the p5.js Editor
Iframe Embed Code
You can add this MicroSim to any web page by adding this to your HTML:
1 2 3 4 | |
About This MicroSim
A NeoPixel seven-segment digit is a short strip of addressable LEDs cut and placed so that each of the seven segments, a to g, holds two pixels. The strip is one long chain, so every pixel has a number from 0 to 13 in the order the data travels. Your program needs a lookup table that says which pixel numbers belong to which segment:
1 2 | |
The digit bytes are the same ones used for the seven-segment display in Chapter 9: bit 0 is segment a, bit 1 is b, and so on up to bit 6 for g. To show a digit, the program checks each bit and lights both pixels of every segment whose bit is 1.
The wiring order is a design choice. The default runs the strip around the outside of the digit (a to f) and then jumps back for the middle segment g. Other orders can need shorter jumper wires between segments. The strip path length in the panel measures the total distance the strip travels from pixel 0 to pixel 13, so you can compare designs.
How to Use
- Pick a Digit from 0 to 9. The lit segments turn red, and the panel shows the digit's byte, its segments, and the pixel numbers that light.
- Click any segment to see which two pixels it contains.
- Check Show strip order to draw the strip's path from the data-in (DIN) end through all 14 pixels.
- Press Rewire, then click the seven segments in the order you want the strip to pass through them. The pixel numbers and the
SEG_PIXELSlist update. Press Reset wiring to go back toatogorder. - Press Copy SEG_PIXELS to copy the Python line for your design to the clipboard. (If your browser blocks copying inside the page, select the line in the panel instead.)
Lesson Plan
Learning Objective
Students will design a pixel-to-segment mapping and apply it to display a digit (Bloom: Applying, Creating).
Grade Level
9-12 (Clocks and Watches with AI)
Duration
15-20 minutes
Prerequisites
- Seven-segment patterns and segment bytes (Chapter 9)
- NeoPixel indexing and
np[i] = (r, g, b)(Chapter 16) - Bit shifts and masks (Chapter 8)
Activities
- Apply (4 min): For digits 1, 4, and 8, students predict the lit pixel numbers from the
DIGITSbyte, then check with the menu. - Trace (3 min): With Show strip order on, students find the longest jump in the default wiring.
- Design (6 min): Students rewire the digit to make the strip path as short as possible and record the path length and their
SEG_PIXELSlist. - Test in code (5 min): Students paste their
SEG_PIXELSinto the chapter'sshow_digit()function and explain why the rest of the program does not need to change.
Assessment
- With the default wiring, which pixels light for the digit 2 (
0x5B)? (Segments a, b, d, e, g: pixels 0, 1, 2, 3, 6, 7, 8, 9, 12, 13.) - How many pixels does a four-digit clock with a two-pixel colon need? (58.)
- Explain why changing the wiring order changes
SEG_PIXELSbut notDIGITS.
References
- Seven-segment display - Wikipedia; segment names and digit patterns.
- Adafruit NeoPixel Uberguide - How addressable LED strips are wired and indexed.
- MicroPython neopixel module - The driver used on the Pico.