Guest User

Untitled

a guest
Jan 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  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. import sys
  11. sys.path.append('/Adafruit_CircuitPython_BitmapFont')
  12. sys.path.append('/Adafruit_CircuitPython_Display_Text')
  13. print(sys.path)
  14.  
  15. from adafruit_bitmap_font import bitmap_font
  16. from adafruit_display_text.text_area import TextArea
  17.  
  18. backlight = pulseio.PWMOut(board.TFT_BACKLIGHT)
  19.  
  20. max_brightness = 2 ** 15
  21.  
  22. fonts = list(filter(lambda x: x.endswith("bdf") and not x.startswith("."), os.listdir("/")))
  23. font = bitmap_font.load_font(fonts[0])
  24.  
  25. start = time.monotonic()
  26. code_points = set()
  27. code_points.update(range(0x30, 0x7a))
  28. code_points.add(0x20)
  29. font.load_glyphs(code_points)
  30. print("pre-load time:", time.monotonic() - start)
  31.  
  32. print("fade up")
  33. # Fade up the backlight
  34. for b in range(100):
  35. backlight.duty_cycle = b * max_brightness // 100
  36. time.sleep(0.01) # default (0.01)
  37.  
  38. demos = ["Hackaday", "0123456789"]
  39.  
  40. splash = displayio.Group(max_size=len(fonts) * len(demos))
  41. board.DISPLAY.show(splash)
  42. max_y = 0
  43. y = 2
  44.  
  45. print("Font load {}".format(font.name))
  46. start = time.monotonic()
  47. area = TextArea(font, text=" Hack A Day")
  48. print("text load time:", time.monotonic() - start)
  49. area.y = y
  50. splash.append(area.group)
  51. # Wait for the image to load.
  52. board.DISPLAY.wait_for_frame()
  53.  
  54. for i in range(1000):
  55. area = TextArea(font, text='Skulls: {0:<10}'.format(i))
  56. area.y = 200
  57. #area.x = 100
  58. if i != 0:
  59. splash.pop()
  60. splash.append(area.group)
  61. board.DISPLAY.wait_for_frame()
  62. #time.sleep(1)
  63. gc.collect()
  64. print("mem free:", gc.mem_free())
  65.  
  66. # Fade down the backlight
  67. for b in range(50, -1, -1):
  68. backlight.duty_cycle = b * max_brightness // 100
  69. time.sleep(0.005) # default (0.005)
  70.  
  71. print("fade down")
  72.  
  73. # splash.pop()
Add Comment
Please, Sign In to add comment