stmpe610_paint_demo.py
1 """ 2 Simple painting demo that draws on an Adafruit capacitive touch shield with 3 ILI9341 display and STMPE610 resistive touch driver 4 """ 5 6 import busio 7 import board 8 import digitalio 9 import adafruit_stmpe610 10 from adafruit_rgb_display import ili9341, color565 11 12 # Create library object using our Bus SPI port 13 spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO) 14 15 # Adafruit Metro M0 + 2.8" Capacitive touch shield 16 cs_pin = digitalio.DigitalInOut(board.D9) 17 dc_pin = digitalio.DigitalInOut(board.D10) 18 19 # Initialize display 20 display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin) 21 # Fill with black! 22 display.fill(color565(0, 0, 0)) 23 24 st_cs_pin = digitalio.DigitalInOut(board.D6) 25 st = adafruit_stmpe610.Adafruit_STMPE610_SPI(spi, st_cs_pin) 26 27 while True: 28 if st.touched: 29 while not st.buffer_empty: 30 ts = st.touches 31 for point in ts: 32 # perform transformation to get into display coordinate system! 33 y = point["y"] 34 x = 4096 - point["x"] 35 x = 2 * x // 30 36 y = 8 * y // 90 37 display.fill_rectangle(x - 2, y - 2, 4, 4, color565(255, 0, 0))