pcd8544_simpletest.py
1 import time 2 import board 3 import busio 4 import digitalio 5 6 import adafruit_pcd8544 7 8 # Initialize SPI bus and control pins 9 spi = busio.SPI(board.SCK, MOSI=board.MOSI) 10 dc = digitalio.DigitalInOut(board.D6) # data/command 11 cs = digitalio.DigitalInOut(board.D5) # Chip select 12 reset = digitalio.DigitalInOut(board.D9) # reset 13 14 display = adafruit_pcd8544.PCD8544(spi, dc, cs, reset) 15 16 display.bias = 4 17 display.contrast = 60 18 19 # Turn on the Backlight LED 20 backlight = digitalio.DigitalInOut(board.D10) # backlight 21 backlight.switch_to_output() 22 backlight.value = True 23 24 print("Pixel test") 25 # Clear the display. Always call show after changing pixels to make the display 26 # update visible! 27 display.fill(0) 28 display.show() 29 30 # Set a pixel in the origin 0,0 position. 31 display.pixel(0, 0, 1) 32 # Set a pixel in the middle position. 33 display.pixel(display.width // 2, display.height // 2, 1) 34 # Set a pixel in the opposite corner position. 35 display.pixel(display.width - 1, display.height - 1, 1) 36 display.show() 37 time.sleep(2) 38 39 print("Lines test") 40 # we'll draw from corner to corner, lets define all the pair coordinates here 41 corners = ( 42 (0, 0), 43 (0, display.height - 1), 44 (display.width - 1, 0), 45 (display.width - 1, display.height - 1), 46 ) 47 48 display.fill(0) 49 for corner_from in corners: 50 for corner_to in corners: 51 display.line(corner_from[0], corner_from[1], corner_to[0], corner_to[1], 1) 52 display.show() 53 time.sleep(2) 54 55 print("Rectangle test") 56 display.fill(0) 57 w_delta = display.width / 10 58 h_delta = display.height / 10 59 for i in range(11): 60 display.rect(0, 0, int(w_delta * i), int(h_delta * i), 1) 61 display.show() 62 time.sleep(2) 63 64 print("Text test") 65 display.fill(0) 66 display.text("hello world", 0, 0, 1) 67 display.text("this is the", 0, 8, 1) 68 display.text("CircuitPython", 0, 16, 1) 69 display.text("adafruit lib-", 0, 24, 1) 70 display.text("rary for the", 0, 32, 1) 71 display.text("PCD8544! :) ", 0, 40, 1) 72 73 display.show() 74 75 while True: 76 display.invert = True 77 time.sleep(0.5) 78 display.invert = False 79 time.sleep(0.5)