Neopixel Seven Segment Clock

We can create a large, bright clock visible in a large classroom by lighting up selective pixels of an LED strip and arranging the pixels in the shape of seven segment displays. We can use three pixels per segment.
![]()
Seven Segment Digits

- We can use three pixels per segment.
 - 21 pixels per digit
 - 63 pixels + 6 for the "1" + two for the colon = 70 pixels
 

Drawing Digits
We can create an array of the segments like this:
1 2 3 4 5 6 7 8 9 10 11 12 13  |  | 
Digit Pixel Map
Assume that a digit starts at pixel n and that each segment has three pixels. To turn on the segments, here is the mapping:
- a: n, n+1, n+2
 - b: n+3, n+4, n+5
 - c: n+6, n+7, n+8
 - d: n+9, n+10, n+11
 
1 2 3 4 5 6 7 8 9 10 11 12  |  | 
Clock Code
Here is some working Python code that displays the time on the clock.
```python from machine import Pin from neopixel import NeoPixel from utime import sleep, localtime
NUMBER_PIXELS = 74 strip = NeoPixel(Pin(0), NUMBER_PIXELS)
Define segment patterns for digits 0-9
Segments in order [a,b,c,d,e,f,g]:
a: top (0,1,2)
b: top right (3,4,5)
c: bottom right (6,7,8)
d: bottom (9,10,11)
e: bottom left (12,13,14)
f: upper left (15,16,17)
g: middle (18,19,20)
DIGITS = { # a,b,c,d,e,f,g 0: [1,1,1,1,1,1,0], # all but middle 1: [0,1,1,0,0,0,0], # right side only 2: [1,1,0,1,1,0,1], # all but bottom right and upper left 3: [1,1,1,1,0,0,1], # all but left side 4: [0,1,1,0,0,1,1], # both right, upper left, and middle 5: [1,0,1,1,0,1,1], # all but top right and bottom left 6: [1,0,1,1,1,1,1], # all but top right 7: [1,1,1,0,0,0,0], # top and both right segments 8: [1,1,1,1,1,1,1], # all segments 9: [1,1,1,1,0,1,1] # all but bottom left }
Color definitions (RGB)
ON_COLOR = (10, 10, 10) # Dim white OFF_COLOR = (0, 0, 0) # Off
def set_segment_pixels(start_idx, segment_pattern): """Set three pixels for a segment based on pattern""" for i in range(3): strip[start_idx + i] = ON_COLOR if segment_pattern else OFF_COLOR
def display_digit(digit, start_pixel): """Display a single digit starting at the specified pixel""" if digit not in DIGITS: return
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  |  | 
def set_colon(on=True): """Set colon pixels (42 and 43)""" color = ON_COLOR if on else OFF_COLOR strip[42] = color strip[43] = color
def display_time(hour, minute, colon_on): """Display time on the LED strip""" # Convert 24-hour to 12-hour format hour = hour if hour <= 12 else hour - 12 if hour == 0: hour = 12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21  |  | 
def clear_display(): """Turn off all pixels""" for i in range(NUMBER_PIXELS): strip[i] = OFF_COLOR strip.write()
Main loop
colon_state = True clear_display()
while True: current_time = localtime() hour = current_time[3] minute = current_time[4] if hour > 12: display_hour = hour - 12
1 2 3 4  |  | 
```