kopia lustrzana https://github.com/peterhinch/micropython-nano-gui
Add aclock_large demo
rodzic
82770e9544
commit
befcfd08ba
|
@ -1,9 +1,9 @@
|
|||
# MicroPython nano-gui
|
||||
|
||||
A lightweight and minimal MicroPython GUI library for display drivers based on
|
||||
the `FrameBuffer` class. Various display technologies are supported, including
|
||||
small color and monochrome OLED's, color TFT's, ePaper and Sharp units. The GUI
|
||||
is cross-platform.
|
||||
the `FrameBuffer` class. It is portable between a range of MicroPython hosts
|
||||
and display devices. Various display technologies are supported, including
|
||||
small color and monochrome OLED's, color TFT's, ePaper and Sharp units.
|
||||
|
||||
These images, most from OLED displays, fail to reproduce the quality of these
|
||||
displays. OLEDs are visually impressive displays with bright colors, wide
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
# ssd1351_esp32.py Customise for your hardware config
|
||||
|
||||
# Released under the MIT License (MIT). See LICENSE.
|
||||
# Copyright (c) 2020 Peter Hinch
|
||||
|
||||
# As written, supports:
|
||||
# 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
|
||||
# Edit the driver import for other displays.
|
||||
|
||||
# Demo of initialisation procedure designed to minimise risk of memory fail
|
||||
# when instantiating the frame buffer. The aim is to do this as early as
|
||||
# possible before importing other modules.
|
||||
|
||||
# WIRING (Adafruit pin nos and names).
|
||||
# ESP SSD
|
||||
# 3v3 Vin (10)
|
||||
# Gnd Gnd (11)
|
||||
# IO27 DC (3 DC)
|
||||
# IO25 CS (5 OC OLEDCS)
|
||||
# IO26 Rst (4 R RESET)
|
||||
# IO14 CLK (2 CL SCK) Hardware SPI1
|
||||
# IO13 DATA (1 SI MOSI)
|
||||
|
||||
import machine
|
||||
import gc
|
||||
|
||||
# *** Choose your color display driver here ***
|
||||
# Driver supporting non-STM platforms
|
||||
from drivers.ssd1351.ssd1351_generic import SSD1351 as SSD
|
||||
|
||||
#height = 96 # 1.27 inch 96*128 (rows*cols) display
|
||||
height = 128 # 1.5 inch 128*128 display
|
||||
|
||||
pdc = Pin(27, Pin.OUT, value=0) # Arbitrary pins
|
||||
pcs = Pin(25, Pin.OUT, value=1)
|
||||
prst = Pin(26, Pin.OUT, value=1)
|
||||
# Datasheet says 20MHz but I couldn't make that work even on a PCB
|
||||
spi = SPI(1, 10_000_000, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
|
||||
gc.collect() # Precaution before instantiating framebuf
|
||||
ssd = SSD(spi, pcs, pdc, prst, height) # Create a display instance
|
|
@ -1,4 +1,5 @@
|
|||
# aclock.py Test/demo program for Adafruit ssd1351-based OLED displays
|
||||
# aclock.py Test/demo program for nanogui
|
||||
# Orinally for ssd1351-based OLED displays but runs on most 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
|
||||
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
# aclock_large.py Test/demo program for displays of 240x240 pixels or larger
|
||||
|
||||
# Released under the MIT License (MIT). See LICENSE.
|
||||
# Copyright (c) 2018-2021 Peter Hinch
|
||||
|
||||
# Initialise hardware and framebuf before importing modules.
|
||||
from color_setup import ssd # Create a display instance
|
||||
from gui.core.nanogui import refresh
|
||||
refresh(ssd, True) # Initialise and clear display.
|
||||
|
||||
# Now import other modules
|
||||
from gui.widgets.label import Label
|
||||
from gui.widgets.dial import Dial, Pointer
|
||||
import cmath
|
||||
import utime
|
||||
from gui.core.writer import CWriter
|
||||
|
||||
# Font for CWriter
|
||||
import gui.fonts.freesans20 as font
|
||||
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, font, GREEN, BLACK, verbose=False)
|
||||
wri.set_clip(True, True, False)
|
||||
|
||||
# Instantiate displayable objects
|
||||
dial = Dial(wri, 2, 2, height = 150, ticks = 12, bdcolor=None, label=240, pip=False) # Border in fg color
|
||||
lbltim = Label(wri, 200, 2, 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()
|
Ładowanie…
Reference in New Issue