I have a lot of boards and usually need to re-use code even for different projects.

full_display_test.py 994B

1234567891011121314151617181920212223242526272829303132333435
  1. import board
  2. import terminalio
  3. from adafruit_display_text import label
  4. from keyboard import Keyboard
  5. # GUIDE
  6. # type freely! CTRL+D clears the text.
  7. # backspace, space, and return function as expected.
  8. # keys not recognised WILL print "UNKNOWN 0x??", but this is useful for extra key scans
  9. ######
  10. keyb = Keyboard()
  11. text = "Press CTRL+D to clear text\n\n"
  12. text_area = label.Label(terminalio.FONT, text=text)
  13. text_area.x = 10
  14. text_area.y = 10
  15. board.DISPLAY.root_group = text_area
  16. while True:
  17. key = keyb.scan()
  18. if key == "BACKSP":
  19. text = text[:-1]
  20. elif key == "CTRLD":
  21. text = "Press CTRL+D to clear text\n\n"
  22. else:
  23. ## WRAPPING
  24. ## calculate wrapping when entering a character
  25. lines = text.split("\n")
  26. current_line = lines[len(lines)-1]
  27. if len(current_line) > 35:
  28. text=text+"\n" # <- start a new line here
  29. ##############################################
  30. text = text+key
  31. text_area.text = text