/ examples / epd_shieldtest.py
epd_shieldtest.py
 1  # EInk Shield test
 2  import time
 3  import digitalio
 4  import busio
 5  import board
 6  from analogio import AnalogIn
 7  from adafruit_epd.epd import Adafruit_EPD
 8  from adafruit_epd.il91874 import Adafruit_IL91874
 9  
10  # create the spi device and pins we will need
11  spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
12  ecs = digitalio.DigitalInOut(board.D10)
13  dc = digitalio.DigitalInOut(board.D9)
14  srcs = digitalio.DigitalInOut(board.D8)  # can be None to use internal memory
15  
16  # give them all to our driver
17  print("Creating display")
18  display = Adafruit_IL91874(
19      176,
20      264,
21      spi,  # 2.7" Tri-color display
22      cs_pin=ecs,
23      dc_pin=dc,
24      sramcs_pin=srcs,
25      rst_pin=None,
26      busy_pin=None,
27  )
28  
29  display.rotation = 1
30  
31  
32  def read_buttons():
33      with AnalogIn(board.A3) as ain:
34          reading = ain.value / 65535
35          if reading > 0.75:
36              return None
37          if reading > 0.4:
38              return 4
39          if reading > 0.25:
40              return 3
41          if reading > 0.13:
42              return 2
43          return 1
44  
45  
46  while True:
47      button = read_buttons()
48      if not button:
49          continue
50      print("Button #%d pressed" % button)
51      if button == 1:
52          print("Clear buffer")
53          display.fill(Adafruit_EPD.WHITE)
54          display.display()
55      if button == 2:
56          print("Draw Rectangles")
57          display.fill_rect(5, 5, 10, 10, Adafruit_EPD.RED)
58          display.rect(0, 0, 20, 30, Adafruit_EPD.BLACK)
59          display.display()
60      if button == 3:
61          print("Draw lines")
62          display.line(0, 0, display.width - 1, display.height - 1, Adafruit_EPD.BLACK)
63          display.line(0, display.height - 1, display.width - 1, 0, Adafruit_EPD.RED)
64          display.display()
65      if button == 4:
66          print("Draw text")
67          display.text("hello world", 25, 10, Adafruit_EPD.BLACK)
68          display.display()
69      time.sleep(0.01)