So Easy MicroPython -NTP Clock, Counter, Timer, …, and IoT Display

Step 1: Upload libraries to your MCU

  • MyKitNeoPixel : A basic library for controlling WS2812B LEDs
  • MyKitNeoPixel7Seq : A special library for display LED strip as clock, timer, counter, … etc

Step 2: How a digital LED clock works ?

  • 1 Digital number is made of 7 LED pixels
  • 1 Clock has 4 digitals plus 2 dots between the digitals of hour and minute
  • 1 Clock is totally made of 30 LEDs, and LED pixels are indexed 0 to 29
The start pixel of 4 digitals are [0, 7, 16, 23], and 2 dot are [14, 15] for 30 pixels of a LED strip
  • Controlling the ON/OFF value of the LED pixels, corresponding to what number 0~9 to be display for a bits array. The lucky thing is you don’t need to worry about how it works, if you use the MyNeoPixel7Seq library I designed. It will handle everything for those troubles for you by itself.

Step 3: Lets’ learn some examples

import utime as time
from MyKitNeoPixel7Seq import myKitNeoPixel7Seq
LED_PIN = 14 # ESP8266: D5
LED_PIXELS = 30 # 30 LEDs for a digital LED clock
LED_BRI = 10 # Brightness set to 10%, to avoid dazzling

np = myKitNeoPixel7Seq(LED_PIN, LED_PIXELS, LED_BRI, text=[0, 7, 16, 23], dots=[14, 15])

*Basic Display

Example 1:Show Numbers

for n in range(4): 
for i in range(10):
np.showChar(i, n) # 0~9 of each 4 digitals
time.sleep_ms(50)

Example 2:Show Dots (blinking)

for _ in range(6):
np.showDots()
np.dot_sw = not np.dot_sw
time.sleep_ms(500)

Example 3:Marquee Text

text = "0123456789-"
temp = text
for _ in range(len(text)):
np.showText(temp[:len(np.text)])
temp = np.strRotate(temp, 1)
time.sleep(0.5)

Example 4:Paging Text

text = "1314520-487-"
for _ in range(6):
np.showText(text[:len(np.text)])
text = np.strRotate(text, 4)
time.sleep(1)

*Counter Display

Example 5:Show Numbers without leading zeros

for num in range(11):
np.showText(str(num), 4, ' ')

Example 6:Show Numbers with leading zeros

for num in range(11):
num_str = np.strFiller(num, 4, '0')
np.showText(num_str)

*Timer Display

Example 7:Count down: every 10 ms

np.showTimer(1111, "c", True). # count 1111 milliseconds

Example 8:Count : every 10 ms

np.showTimer(1111, "c") # count 1111 milliseconds

Example 9:Count down : every second

np.showTimer(11, "s", True) # count 11 seconds

Example 10:Count : every second

np.showTimer(11, "s") # count 11 seconds

Example 11:Count down : every minute

np.showTimer(61, "m") # count 61 minutes

Example 12:Count : every minute

np.showTimer(61, "m") # count 61 minutes

*Clock Display

Example 14:Digital Clock

while True:
np.showClock()
np.dot_sw = not np.dot_sw
time.sleep(0.5)

Example 15:Streamer Clock

while True:
np.showClock360(8) # skip 8 colors in 360 color wheel
np.dot_sw = not np.dot_sw
time.sleep_ms(100)

*Scoreboard Display

Example 16:Two-teams Match

np.showScoreboard(scoreA, scoreB, colorA, colorB)

DEMO : Network NTP Streamer Clock

np.updateMachineTime()    # NTP synchronized MCU
while True:
np.showClock360(8) # skip 8 colors in 360 color wheel
time.sleep_ms(100)

That’s all, so easy right ? Hope this helps !

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store