kopia lustrzana https://github.com/peterhinch/micropython-nano-gui
65 wiersze
2.1 KiB
Python
65 wiersze
2.1 KiB
Python
# aclock.py Test/demo program for Adafruit ssd1351-based OLED displays
|
|
# Adafruit 1.5" 128*128 OLED display: https://www.adafruit.com/product/1431
|
|
# Adafruit 1.27" 128*96 display https://www.adafruit.com/product/1673
|
|
|
|
# Released under the MIT License (MIT). See LICENSE.
|
|
# Copyright (c) 2018-2020 Peter Hinch
|
|
|
|
# WIRING
|
|
# Pyb SSD
|
|
# 3v3 Vin
|
|
# Gnd Gnd
|
|
# X1 DC
|
|
# X2 CS
|
|
# X3 Rst
|
|
# X6 CLK
|
|
# X8 DATA
|
|
|
|
# Initialise hardware
|
|
from ssd1351_setup import ssd, height # Create a display instance
|
|
from gui.core.nanogui import Dial, Pointer, refresh, Label
|
|
refresh(ssd) # Initialise and clear display.
|
|
|
|
# Now import other modules
|
|
import cmath
|
|
import utime
|
|
from gui.core.writer import CWriter
|
|
|
|
# Font for CWriter
|
|
import gui.fonts.arial10 as arial10
|
|
from gui.core.colors import *
|
|
|
|
def aclock():
|
|
uv = lambda phi : cmath.rect(1, phi) # Return a unit vector of phase phi
|
|
pi = cmath.pi
|
|
days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
|
|
'Sunday')
|
|
months = ('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July',
|
|
'Aug', 'Sept', 'Oct', 'Nov', 'Dec')
|
|
# Instantiate CWriter
|
|
CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it
|
|
wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False)
|
|
wri.set_clip(True, True, False)
|
|
|
|
# Instantiate displayable objects
|
|
dial = Dial(wri, 2, 2, height = 75, ticks = 12, bdcolor=None, label=120, pip=False) # Border in fg color
|
|
lbltim = Label(wri, 5, 85, 35)
|
|
hrs = Pointer(dial)
|
|
mins = Pointer(dial)
|
|
secs = Pointer(dial)
|
|
|
|
hstart = 0 + 0.7j # Pointer lengths and position at top
|
|
mstart = 0 + 0.92j
|
|
sstart = 0 + 0.92j
|
|
while True:
|
|
t = utime.localtime()
|
|
hrs.value(hstart * uv(-t[3]*pi/6 - t[4]*pi/360), YELLOW)
|
|
mins.value(mstart * uv(-t[4] * pi/30), YELLOW)
|
|
secs.value(sstart * uv(-t[5] * pi/30), RED)
|
|
lbltim.value('{:02d}.{:02d}.{:02d}'.format(t[3], t[4], t[5]))
|
|
dial.text('{} {} {} {}'.format(days[t[6]], t[2], months[t[1] - 1], t[0]))
|
|
refresh(ssd)
|
|
utime.sleep(1)
|
|
|
|
aclock()
|