kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Badger2040: Fix examples & prep for baking
rodzic
2c27296cc4
commit
2efd7b9655
|
|
@ -5,18 +5,21 @@ from machine import RTC
|
||||||
rtc = RTC()
|
rtc = RTC()
|
||||||
screen = badger2040.Badger2040()
|
screen = badger2040.Badger2040()
|
||||||
screen.update_speed(badger2040.UPDATE_TURBO)
|
screen.update_speed(badger2040.UPDATE_TURBO)
|
||||||
|
screen.font("gothic")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
year, month, day, wd, hour, minute, second, _ = rtc.datetime()
|
year, month, day, wd, hour, minute, second, _ = rtc.datetime()
|
||||||
hms = "{:02} {:02} {:02}".format(hour, minute, second)
|
hms = "{:02}:{:02}:{:02}".format(hour, minute, second)
|
||||||
ymd = "{:04}/{:02}/{:02}".format(year, month, day)
|
ymd = "{:04}/{:02}/{:02}".format(year, month, day)
|
||||||
|
|
||||||
screen.pen(15)
|
screen.pen(15)
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.pen(1)
|
screen.pen(0)
|
||||||
screen.thickness(5)
|
screen.thickness(5)
|
||||||
screen.text(hms, 0, 0, 2.0)
|
screen.text(hms, 0, 40, 1.8)
|
||||||
screen.thickness(3)
|
screen.thickness(3)
|
||||||
screen.text(ymd, 0, 60, 1.0)
|
screen.text(ymd, 0, 100, 1.0)
|
||||||
|
|
||||||
|
screen.update()
|
||||||
|
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,22 @@ import machine
|
||||||
import time
|
import time
|
||||||
import gc
|
import gc
|
||||||
|
|
||||||
|
try:
|
||||||
|
open("witw.txt", "r")
|
||||||
|
except OSError:
|
||||||
|
try:
|
||||||
|
import witw
|
||||||
|
open("witw.txt", "wb").write(witw.data())
|
||||||
|
del witw
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
|
|
||||||
# **** Put the name of your text file here *****
|
# **** Put the name of your text file here *****
|
||||||
text_file = "289-0.txt" # File must be on the MicroPython device
|
text_file = "witw.txt" # File must be on the MicroPython device
|
||||||
|
|
||||||
# Global Constants
|
# Global Constants
|
||||||
WIDTH = badger2040.WIDTH
|
WIDTH = badger2040.WIDTH
|
||||||
|
|
|
||||||
|
|
@ -4,19 +4,27 @@ import time
|
||||||
import math
|
import math
|
||||||
import machine
|
import machine
|
||||||
import badger2040
|
import badger2040
|
||||||
|
import launchericons
|
||||||
|
|
||||||
page = 0
|
page = 0
|
||||||
|
font_size = 1
|
||||||
|
|
||||||
|
icons = bytearray(launchericons.data())
|
||||||
|
|
||||||
examples = [
|
examples = [
|
||||||
"clock.py",
|
("clock.py", 0),
|
||||||
"fonts.py",
|
("fonts.py", 1),
|
||||||
"clean.py",
|
("ebook.py", 2),
|
||||||
"interrupt.py",
|
("image.py", 3),
|
||||||
"scanline.py",
|
("list.py", 4),
|
||||||
"lut-test.py",
|
("badge.py", 5)
|
||||||
"quictest.py"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
font_sizes = (0.5, 0.7, 0.9)
|
||||||
|
|
||||||
|
# Approximate center lines for buttons A, B and C
|
||||||
|
centers = (41, 147, 253)
|
||||||
|
|
||||||
MAX_PAGE = math.ceil(len(examples) / 3)
|
MAX_PAGE = math.ceil(len(examples) / 3)
|
||||||
|
|
||||||
button_a = machine.Pin(badger2040.BUTTON_A, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
button_a = machine.Pin(badger2040.BUTTON_A, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
||||||
|
|
@ -25,40 +33,42 @@ button_c = machine.Pin(badger2040.BUTTON_C, machine.Pin.IN, machine.Pin.PULL_DOW
|
||||||
button_up = machine.Pin(badger2040.BUTTON_UP, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
button_up = machine.Pin(badger2040.BUTTON_UP, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
||||||
button_down = machine.Pin(badger2040.BUTTON_DOWN, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
button_down = machine.Pin(badger2040.BUTTON_DOWN, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
||||||
|
|
||||||
# Early exit if b + c button is pressed
|
# Inverted. For reasons.
|
||||||
# A button must be held briefly to power on, so we use a combo instead
|
button_user = machine.Pin(badger2040.BUTTON_USER, machine.Pin.IN, machine.Pin.PULL_UP)
|
||||||
if button_b.value() and button_c.value():
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
|
display = badger2040.Badger2040()
|
||||||
screen = badger2040.Badger2040()
|
display.update_speed(1)
|
||||||
screen.update_speed(1)
|
|
||||||
|
|
||||||
|
|
||||||
def render():
|
def render():
|
||||||
screen.pen(15)
|
display.pen(15)
|
||||||
screen.clear()
|
display.clear()
|
||||||
screen.pen(0)
|
display.pen(0)
|
||||||
screen.thickness(2)
|
display.thickness(2)
|
||||||
|
|
||||||
max_icons = min(3, len(examples[(page * 3):]))
|
max_icons = min(3, len(examples[(page * 3):]))
|
||||||
|
|
||||||
for i in range(max_icons):
|
for i in range(max_icons):
|
||||||
x = (14 + 80) * i + 14
|
x = centers[i]
|
||||||
label = examples[i + (page * 3)].replace(".py", "")
|
label, icon = examples[i + (page * 3)]
|
||||||
screen.rectangle(x, 24, 80, 80)
|
label = label.replace(".py", "")
|
||||||
screen.text(label, x, 24 + 80 + 10, 0.5)
|
display.pen(0)
|
||||||
|
display.icon(icons, icon, 384, 64, x - 32, 24)
|
||||||
|
w = display.measure_text(label, font_sizes[font_size])
|
||||||
|
display.text(label, x - int(w / 2), 16 + 80, font_sizes[font_size])
|
||||||
|
|
||||||
for i in range(MAX_PAGE):
|
for i in range(MAX_PAGE):
|
||||||
x = 286
|
x = 286
|
||||||
y = int((128 / 2) - (MAX_PAGE * 10 / 2) + (i * 10))
|
y = int((128 / 2) - (MAX_PAGE * 10 / 2) + (i * 10))
|
||||||
screen.pen(0)
|
display.pen(0)
|
||||||
screen.rectangle(x, y, 8, 8)
|
display.rectangle(x, y, 8, 8)
|
||||||
if page != i:
|
if page != i:
|
||||||
screen.pen(15)
|
display.pen(15)
|
||||||
screen.rectangle(x + 1, y + 1, 6, 6)
|
display.rectangle(x + 1, y + 1, 6, 6)
|
||||||
|
|
||||||
screen.update()
|
display.pen(0)
|
||||||
|
|
||||||
|
display.update()
|
||||||
|
|
||||||
|
|
||||||
def launch(file):
|
def launch(file):
|
||||||
|
|
@ -67,18 +77,24 @@ def launch(file):
|
||||||
del locals()[k]
|
del locals()[k]
|
||||||
gc.collect()
|
gc.collect()
|
||||||
__import__(file)
|
__import__(file)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
def launch_example(index):
|
def launch_example(index):
|
||||||
try:
|
try:
|
||||||
launch(examples[(page * 3) + index])
|
launch(examples[(page * 3) + index][0])
|
||||||
return True
|
return True
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def button(pin):
|
def button(pin):
|
||||||
global page
|
global page, font_size
|
||||||
|
if pin == button_user:
|
||||||
|
font_size += 1
|
||||||
|
if font_size == len(font_sizes):
|
||||||
|
font_size = 0
|
||||||
|
render()
|
||||||
if pin == button_a:
|
if pin == button_a:
|
||||||
launch_example(0)
|
launch_example(0)
|
||||||
if pin == button_b:
|
if pin == button_b:
|
||||||
|
|
@ -102,12 +118,18 @@ while button_a.value() or button_b.value() or button_c.value() or button_up.valu
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
button_a.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
|
||||||
button_b.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
|
||||||
button_c.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
|
||||||
button_up.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
|
||||||
button_down.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1.0)
|
if button_a.value():
|
||||||
|
button(button_a)
|
||||||
|
if button_b.value():
|
||||||
|
button(button_b)
|
||||||
|
if button_c.value():
|
||||||
|
button(button_c)
|
||||||
|
if button_up.value():
|
||||||
|
button(button_up)
|
||||||
|
if button_down.value():
|
||||||
|
button(button_down)
|
||||||
|
if not button_user.value():
|
||||||
|
button(button_user)
|
||||||
|
|
||||||
|
time.sleep(0.01)
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue