/ examples / display_text_pyportal.py
display_text_pyportal.py
 1  """
 2  This example show the use of the backlight as well as using labels to simulate
 3  a terminal using a font on the PyPortal
 4  """
 5  
 6  import os
 7  import time
 8  import board
 9  import displayio
10  
11  from adafruit_bitmap_font import bitmap_font
12  from adafruit_display_text.label import Label
13  
14  fonts = list(
15      filter(lambda x: x.endswith("bdf") and not x.startswith("."), os.listdir("/"))
16  )
17  fonts = [bitmap_font.load_font(x) for x in fonts]
18  
19  print("fade up")
20  # Fade up the backlight
21  for b in range(100):
22      board.DISPLAY.brightness = b / 100
23      time.sleep(0.01)  # default (0.01)
24  
25  demos = ["CircuitPython = Code + Community", "accents - üàêùéáçãÍóí", "others - αψ◌"]
26  
27  splash = displayio.Group(max_size=len(fonts) * len(demos))
28  board.DISPLAY.show(splash)
29  max_y = 0
30  y = 2
31  for demo_text in demos:
32      for font in fonts:
33          print("Font load {}".format(font.name))
34          area = Label(font, text=demo_text)
35          area.y = y
36          splash.append(area)
37  
38          y += area.height
39  
40          # Wait for the image to load.
41          try:
42              board.DISPLAY.refresh(target_frames_per_second=60)
43          except AttributeError:
44              board.DISPLAY.wait_for_frame()
45  
46  # Wait for 10 minutes (600 seconds)
47  time.sleep(600)
48  
49  # Fade down the backlight
50  for b in range(100, -1, -1):
51      board.DISPLAY.brightness = b / 100
52      time.sleep(0.01)  # default (0.01)
53  
54  print("fade down")
55  
56  time.sleep(10)