Badger2040: Fixup examples for Act LED and A+C to exit.
This commit is contained in:
parent
a862a6d310
commit
d3c8811656
|
@ -172,16 +172,17 @@ def draw_badge():
|
||||||
|
|
||||||
# Create a new Badger and set it to update NORMAL
|
# Create a new Badger and set it to update NORMAL
|
||||||
display = badger2040.Badger2040()
|
display = badger2040.Badger2040()
|
||||||
|
display.led(128)
|
||||||
display.update_speed(badger2040.UPDATE_NORMAL)
|
display.update_speed(badger2040.UPDATE_NORMAL)
|
||||||
|
|
||||||
# Open the badge file
|
# Open the badge file
|
||||||
try:
|
try:
|
||||||
badge = open("badge.txt", "r")
|
badge = open("badge.txt", "r")
|
||||||
except OSError:
|
except OSError:
|
||||||
badge = open("badge.txt", "w")
|
with open("badge.txt", "w") as f:
|
||||||
badge.write(DEFAULT_TEXT)
|
f.write(DEFAULT_TEXT)
|
||||||
badge.flush()
|
f.flush()
|
||||||
badge.seek(0)
|
badge = open("badge.txt", "r")
|
||||||
|
|
||||||
# Read in the next 6 lines
|
# Read in the next 6 lines
|
||||||
company = badge.readline() # "mustelid inc"
|
company = badge.readline() # "mustelid inc"
|
||||||
|
|
|
@ -4,9 +4,10 @@ import badger2040
|
||||||
|
|
||||||
|
|
||||||
rtc = machine.RTC()
|
rtc = machine.RTC()
|
||||||
screen = badger2040.Badger2040()
|
display = badger2040.Badger2040()
|
||||||
screen.update_speed(badger2040.UPDATE_TURBO)
|
display.led(128)
|
||||||
screen.font("gothic")
|
display.update_speed(badger2040.UPDATE_TURBO)
|
||||||
|
display.font("gothic")
|
||||||
|
|
||||||
cursors = ["year", "month", "day", "hour", "minute"]
|
cursors = ["year", "month", "day", "hour", "minute"]
|
||||||
set_clock = False
|
set_clock = False
|
||||||
|
@ -36,6 +37,9 @@ def button(pin):
|
||||||
if not pin.value():
|
if not pin.value():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if button_a.value() and button_c.value():
|
||||||
|
machine.reset()
|
||||||
|
|
||||||
adjust = 0
|
adjust = 0
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
|
@ -94,42 +98,42 @@ def draw_clock():
|
||||||
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)
|
||||||
|
|
||||||
hms_width = screen.measure_text(hms, 1.8)
|
hms_width = display.measure_text(hms, 1.8)
|
||||||
hms_offset = int((badger2040.WIDTH / 2) - (hms_width / 2))
|
hms_offset = int((badger2040.WIDTH / 2) - (hms_width / 2))
|
||||||
h_width = screen.measure_text(hms[0:2], 1.8)
|
h_width = display.measure_text(hms[0:2], 1.8)
|
||||||
mi_width = screen.measure_text(hms[3:5], 1.8)
|
mi_width = display.measure_text(hms[3:5], 1.8)
|
||||||
mi_offset = screen.measure_text(hms[0:3], 1.8)
|
mi_offset = display.measure_text(hms[0:3], 1.8)
|
||||||
|
|
||||||
ymd_width = screen.measure_text(ymd, 1.0)
|
ymd_width = display.measure_text(ymd, 1.0)
|
||||||
ymd_offset = int((badger2040.WIDTH / 2) - (ymd_width / 2))
|
ymd_offset = int((badger2040.WIDTH / 2) - (ymd_width / 2))
|
||||||
y_width = screen.measure_text(ymd[0:4], 1.0)
|
y_width = display.measure_text(ymd[0:4], 1.0)
|
||||||
m_width = screen.measure_text(ymd[5:7], 1.0)
|
m_width = display.measure_text(ymd[5:7], 1.0)
|
||||||
m_offset = screen.measure_text(ymd[0:5], 1.0)
|
m_offset = display.measure_text(ymd[0:5], 1.0)
|
||||||
d_width = screen.measure_text(ymd[8:10], 1.0)
|
d_width = display.measure_text(ymd[8:10], 1.0)
|
||||||
d_offset = screen.measure_text(ymd[0:8], 1.0)
|
d_offset = display.measure_text(ymd[0:8], 1.0)
|
||||||
|
|
||||||
screen.pen(15)
|
display.pen(15)
|
||||||
screen.clear()
|
display.clear()
|
||||||
screen.pen(0)
|
display.pen(0)
|
||||||
screen.thickness(5)
|
display.thickness(5)
|
||||||
screen.text(hms, hms_offset, 40, 1.8)
|
display.text(hms, hms_offset, 40, 1.8)
|
||||||
screen.thickness(3)
|
display.thickness(3)
|
||||||
screen.text(ymd, ymd_offset, 100, 1.0)
|
display.text(ymd, ymd_offset, 100, 1.0)
|
||||||
|
|
||||||
if set_clock:
|
if set_clock:
|
||||||
if cursors[cursor] == "year":
|
if cursors[cursor] == "year":
|
||||||
screen.line(ymd_offset, 120, ymd_offset + y_width, 120)
|
display.line(ymd_offset, 120, ymd_offset + y_width, 120)
|
||||||
if cursors[cursor] == "month":
|
if cursors[cursor] == "month":
|
||||||
screen.line(ymd_offset + m_offset, 120, ymd_offset + m_offset + m_width, 120)
|
display.line(ymd_offset + m_offset, 120, ymd_offset + m_offset + m_width, 120)
|
||||||
if cursors[cursor] == "day":
|
if cursors[cursor] == "day":
|
||||||
screen.line(ymd_offset + d_offset, 120, ymd_offset + d_offset + d_width, 120)
|
display.line(ymd_offset + d_offset, 120, ymd_offset + d_offset + d_width, 120)
|
||||||
|
|
||||||
if cursors[cursor] == "hour":
|
if cursors[cursor] == "hour":
|
||||||
screen.line(hms_offset, 70, hms_offset + h_width, 70)
|
display.line(hms_offset, 70, hms_offset + h_width, 70)
|
||||||
if cursors[cursor] == "minute":
|
if cursors[cursor] == "minute":
|
||||||
screen.line(hms_offset + mi_offset, 70, hms_offset + mi_offset + mi_width, 70)
|
display.line(hms_offset + mi_offset, 70, hms_offset + mi_offset + mi_width, 70)
|
||||||
|
|
||||||
screen.update()
|
display.update()
|
||||||
|
|
||||||
|
|
||||||
year, month, day, wd, hour, minute, second, _ = rtc.datetime()
|
year, month, day, wd, hour, minute, second, _ = rtc.datetime()
|
||||||
|
|
|
@ -92,6 +92,7 @@ current_page = 0
|
||||||
|
|
||||||
# Create a new Badger and set it to update FAST
|
# Create a new Badger and set it to update FAST
|
||||||
display = badger2040.Badger2040()
|
display = badger2040.Badger2040()
|
||||||
|
display.led(128)
|
||||||
display.update_speed(badger2040.UPDATE_FAST)
|
display.update_speed(badger2040.UPDATE_FAST)
|
||||||
|
|
||||||
# Set up the buttons
|
# Set up the buttons
|
||||||
|
@ -100,9 +101,8 @@ button_up = machine.Pin(badger2040.BUTTON_UP, machine.Pin.IN, machine.Pin.PULL_D
|
||||||
|
|
||||||
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)
|
||||||
button_b = machine.Pin(badger2040.BUTTON_B, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
button_b = machine.Pin(badger2040.BUTTON_B, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
||||||
|
button_c = machine.Pin(badger2040.BUTTON_C, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
||||||
|
|
||||||
# Set up the activity LED
|
|
||||||
led = machine.Pin(badger2040.PIN_LED, machine.Pin.OUT)
|
|
||||||
|
|
||||||
offsets = []
|
offsets = []
|
||||||
|
|
||||||
|
@ -111,6 +111,13 @@ offsets = []
|
||||||
def button(pin):
|
def button(pin):
|
||||||
global next_page, prev_page, change_font_size, change_font
|
global next_page, prev_page, change_font_size, change_font
|
||||||
|
|
||||||
|
time.sleep(0.05)
|
||||||
|
if not pin.value():
|
||||||
|
return
|
||||||
|
|
||||||
|
if button_a.value() and button_c.value():
|
||||||
|
machine.reset()
|
||||||
|
|
||||||
if pin == button_down:
|
if pin == button_down:
|
||||||
next_page = True
|
next_page = True
|
||||||
|
|
||||||
|
@ -129,6 +136,7 @@ button_down.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
||||||
button_up.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
button_up.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
||||||
button_a.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
button_a.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
||||||
button_b.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)
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------
|
# ------------------------------
|
||||||
|
|
|
@ -96,6 +96,7 @@ pressed = False
|
||||||
|
|
||||||
# Create a new Badger and set it to update FAST
|
# Create a new Badger and set it to update FAST
|
||||||
display = badger2040.Badger2040()
|
display = badger2040.Badger2040()
|
||||||
|
display.led(128)
|
||||||
display.update_speed(badger2040.UPDATE_FAST)
|
display.update_speed(badger2040.UPDATE_FAST)
|
||||||
|
|
||||||
# Set up the buttons
|
# Set up the buttons
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import badger2040
|
import badger2040
|
||||||
import time
|
|
||||||
from badger2040 import WIDTH
|
from badger2040 import WIDTH
|
||||||
|
|
||||||
TEXT_SIZE = 0.45
|
TEXT_SIZE = 0.45
|
||||||
LINE_HEIGHT = 16
|
LINE_HEIGHT = 16
|
||||||
|
|
||||||
display = badger2040.Badger2040()
|
display = badger2040.Badger2040()
|
||||||
|
display.led(128)
|
||||||
|
|
||||||
display.pen(0)
|
display.pen(0)
|
||||||
display.rectangle(0, 0, WIDTH, 16)
|
display.rectangle(0, 0, WIDTH, 16)
|
||||||
display.thickness(1)
|
display.thickness(1)
|
||||||
|
@ -27,7 +28,7 @@ y += LINE_HEIGHT
|
||||||
y += LINE_HEIGHT
|
y += LINE_HEIGHT
|
||||||
|
|
||||||
display.thickness(2)
|
display.thickness(2)
|
||||||
display.text("Holding USER button:", 0, y, TEXT_SIZE)
|
display.text("Hold USER after:", 0, y, TEXT_SIZE)
|
||||||
display.thickness(1)
|
display.thickness(1)
|
||||||
y += LINE_HEIGHT
|
y += LINE_HEIGHT
|
||||||
display.text("Up / Down - Change font size", 0, y, TEXT_SIZE)
|
display.text("Up / Down - Change font size", 0, y, TEXT_SIZE)
|
||||||
|
@ -36,5 +37,4 @@ display.text("a - Toggle invert", 0, y, TEXT_SIZE)
|
||||||
y += LINE_HEIGHT
|
y += LINE_HEIGHT
|
||||||
|
|
||||||
display.update()
|
display.update()
|
||||||
while True:
|
display.halt()
|
||||||
time.sleep(1)
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import badger2040
|
import badger2040
|
||||||
import time
|
|
||||||
from badger2040 import WIDTH
|
from badger2040 import WIDTH
|
||||||
|
|
||||||
TEXT_SIZE = 0.45
|
TEXT_SIZE = 0.45
|
||||||
LINE_HEIGHT = 16
|
LINE_HEIGHT = 16
|
||||||
|
|
||||||
display = badger2040.Badger2040()
|
display = badger2040.Badger2040()
|
||||||
|
display.led(128)
|
||||||
|
|
||||||
display.pen(0)
|
display.pen(0)
|
||||||
display.rectangle(0, 0, WIDTH, 16)
|
display.rectangle(0, 0, WIDTH, 16)
|
||||||
display.thickness(1)
|
display.thickness(1)
|
||||||
|
@ -33,6 +34,4 @@ y += LINE_HEIGHT
|
||||||
display.text("https://pimoroni.com/badger2040", 0, y, TEXT_SIZE)
|
display.text("https://pimoroni.com/badger2040", 0, y, TEXT_SIZE)
|
||||||
|
|
||||||
display.update()
|
display.update()
|
||||||
|
display.halt()
|
||||||
while True:
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
|
@ -143,6 +143,7 @@ items_per_page = 0
|
||||||
|
|
||||||
# Create a new Badger and set it to update FAST
|
# Create a new Badger and set it to update FAST
|
||||||
display = badger2040.Badger2040()
|
display = badger2040.Badger2040()
|
||||||
|
display.led(128)
|
||||||
display.update_speed(badger2040.UPDATE_FAST)
|
display.update_speed(badger2040.UPDATE_FAST)
|
||||||
|
|
||||||
# Set up the buttons
|
# Set up the buttons
|
||||||
|
@ -177,6 +178,13 @@ items_per_page = ((LIST_HEIGHT // ITEM_SPACING) + 1) * list_columns
|
||||||
def button(pin):
|
def button(pin):
|
||||||
global update, current_item, needs_save
|
global update, current_item, needs_save
|
||||||
|
|
||||||
|
time.sleep(0.05)
|
||||||
|
if not pin.value():
|
||||||
|
return
|
||||||
|
|
||||||
|
if button_a.value() and button_c.value():
|
||||||
|
machine.reset()
|
||||||
|
|
||||||
if len(list_content) > 0 and not update:
|
if len(list_content) > 0 and not update:
|
||||||
if pin == button_a:
|
if pin == button_a:
|
||||||
if current_item > 0:
|
if current_item > 0:
|
||||||
|
|
|
@ -7,8 +7,8 @@ import time
|
||||||
try:
|
try:
|
||||||
text = open("qrcode.txt", "r")
|
text = open("qrcode.txt", "r")
|
||||||
except OSError:
|
except OSError:
|
||||||
text = open("qrcode.txt", "w")
|
with open("qrcode.txt", "w") as text:
|
||||||
text.write("""https://pimoroni.com/badger2040
|
text.write("""https://pimoroni.com/badger2040
|
||||||
Badger 2040
|
Badger 2040
|
||||||
* 296x128 1-bit e-ink
|
* 296x128 1-bit e-ink
|
||||||
* six user buttons
|
* six user buttons
|
||||||
|
@ -18,8 +18,8 @@ Badger 2040
|
||||||
Scan this code to learn
|
Scan this code to learn
|
||||||
more about Badger 2040.
|
more about Badger 2040.
|
||||||
""")
|
""")
|
||||||
text.flush()
|
text.flush()
|
||||||
text.seek(0)
|
text = open("qrcode.txt", "r")
|
||||||
|
|
||||||
|
|
||||||
lines = text.read().strip().split("\n")
|
lines = text.read().strip().split("\n")
|
||||||
|
@ -28,6 +28,7 @@ title_text = lines.pop(0)
|
||||||
detail_text = lines
|
detail_text = lines
|
||||||
|
|
||||||
display = badger2040.Badger2040()
|
display = badger2040.Badger2040()
|
||||||
|
display.led(128)
|
||||||
code = qrcode.QRCode()
|
code = qrcode.QRCode()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue