Skip to content

Commit 5c41913

Browse files
committed
Add example
1 parent f6bf341 commit 5c41913

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

examples/pyportal.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import board
2+
import displayio
3+
import os
4+
import gc
5+
import pulseio
6+
import random
7+
import time
8+
import microcontroller
9+
10+
from adafruit_bitmap_font import bitmap_font
11+
from adafruit_display_text.text_area import TextArea
12+
13+
backlight = pulseio.PWMOut(microcontroller.pin.PB21)
14+
15+
max_brightness = 2 ** 15
16+
17+
fonts = list(filter(lambda x: x.endswith("bdf") and not x.startswith("."), os.listdir("/")))
18+
fonts = [bitmap_font.load_font(x) for x in fonts]
19+
20+
21+
print("fade up")
22+
# Fade up the backlight
23+
for b in range(100):
24+
backlight.duty_cycle = b * max_brightness // 100
25+
time.sleep(0.01) # default (0.01)
26+
27+
demos = ["CircuitPython = Code + Community", "accents - üàêùéáçãÍóí", "others - αψ◌"]
28+
29+
splash = displayio.Group(max_size=len(fonts) * len(demos))
30+
board.DISPLAY.show(splash)
31+
max_y = 0
32+
y = 2
33+
for demo_text in demos:
34+
for font in fonts:
35+
print("Font load {}".format(font.name))
36+
area = TextArea(font, text=demo_text)
37+
area.y = y
38+
splash.append(area.group)
39+
40+
y += area.height
41+
42+
# Wait for the image to load.
43+
board.DISPLAY.wait_for_frame()
44+
gc.collect()
45+
print("mem free:", gc.mem_free())
46+
47+
# Wait forever
48+
time.sleep(600)
49+
50+
# Fade down the backlight
51+
for b in range(50, -1, -1):
52+
backlight.duty_cycle = b * max_brightness // 100
53+
time.sleep(0.005) # default (0.005)
54+
55+
print("fade down")
56+
57+
# splash.pop()

0 commit comments

Comments
 (0)