Advertisement
xWAFFELx

gc9ao1_cirque_pico.py

Oct 27th, 2023 (edited)
1,454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.33 KB | Source Code | 0 0
  1. # gc9a01_test.py -- fakey lissajous in Micropython
  2. # 21 Oct 2023 - @todbot / Tod Kurt
  3. # Uses Micropython UF2 from https://github.com/russhughes/gc9a01_mpy
  4. # but it seems pretty unstable, wiping out the entire flash contents
  5. # and requiring a reinstall of Micropython.
  6. # And the font mpy files provided do not work with the provided UF2.
  7. #
  8. # Cirque 40mm touchpad code added. -Ticktok
  9. # Requires Adafruit Blinka library to use circuitpython libraries with micropython
  10. #   https://learn.adafruit.com/circuitpython-libraries-on-micropython-using-the-raspberry-pi-pico/installing-blinka-and-libraries
  11. # Requires Cirque touchpad circuitpython library.
  12. #   https://github.com/2bndy5/CircuitPython_Cirque_Pinnacle
  13.  
  14. #micropython libraries for gc9ao1
  15. import random, math, time
  16. from machine import Pin, SPI
  17. import gc9a01
  18. #import vga1_bold_16x32 as font #Need to find a non .mpy version as micropython doesn't support mpy libraries.
  19.  
  20. #circuitpython libraries for trackpad
  21. import board
  22. import busio
  23. from digitalio import DigitalInOut
  24. import circuitpython_cirque_pinnacle.glidepoint as Pinnacle
  25.  
  26.  
  27.  
  28. def mapRange(value, inMin, inMax, outMin, outMax):
  29.     return int(outMin + (((value - inMin) / (inMax - inMin)) * (outMax - outMin)))
  30.    
  31. def draw_dot(tft, x,y,c):
  32.     tft.pixel( x,y, c )
  33.     tft.pixel( x+1, y-1, c )
  34.     tft.pixel( x+1, y+1, c )
  35.     tft.pixel( x-1, y+0, c )
  36.     tft.pixel( x+1, y-1, c )
  37.  
  38. def main():
  39.     dr_pin = DigitalInOut(board.GP11)
  40.     ss_pin = DigitalInOut(board.GP13)
  41.     sck_pin = board.GP14
  42.     mosi_pin = board.GP15
  43.     miso_pin = board.GP12
  44.    
  45.     cirque_spi = busio.SPI(clock=sck_pin, MISO=miso_pin, MOSI=mosi_pin)
  46.     tpad = Pinnacle.PinnacleTouchSPI(cirque_spi, ss_pin, dr_pin=dr_pin)
  47.    
  48.     tpad.data_mode = Pinnacle.ABSOLUTE
  49.    
  50.     spi = SPI(1, baudrate=60_000_000, sck=Pin(14), mosi=Pin(15))
  51.     tft = gc9a01.GC9A01(
  52.         spi,
  53.         240,
  54.         240,
  55.         reset=Pin(8, Pin.OUT),
  56.         cs=Pin(9, Pin.OUT),
  57.         dc=Pin(10, Pin.OUT),
  58.         rotation=1) # 2 == 180 degrees, because of course it does
  59.  
  60.     tft.init()
  61.  
  62.     x,y = 0,0
  63.     r = 60
  64.     phi = 0
  65.     tft.fill(0)
  66.  
  67.     num_trails = 10
  68.     trails = []
  69.  
  70.     while True:
  71.        
  72.         data = tpad.report()
  73.        
  74.         # erase oldest trail element
  75.         if len(trails) > num_trails:
  76.             #print("hit num_trails:", x,y)
  77.             xe,ye = trails.pop(0)  # remove oldest element
  78.             #tft.text( font, "!", xe,ye, gc9a01.color565( 0,0,0), gc9a01.color565(0,0,0) )
  79.             tft.pixel( xe,ye, gc9a01.color565( 0,0,0) )
  80.  
  81.         # draw trail
  82.         for (xt,yt) in trails:
  83.             #print(x,y)
  84.             #tft.text( font, "!", xt,yt, gc9a01.color565( 100,100,0), gc9a01.color565(0,0,0) )
  85.             tft.pixel( xt,yt, gc9a01.color565( 100,100,0) )
  86.            
  87.         if data is None:
  88.             # get new position
  89.             phi += 0.05
  90.             x = 120 + int(r * math.sin( phi ))
  91.             y = 120 + int(r * math.cos( phi ))
  92.         else:
  93.             x = mapRange(data[1],0,1900,0,255)
  94.             y = mapRange(data[2],0,1900,0,255)
  95.        
  96.         print(f"x:{x} y:{y}")
  97.        
  98.         trails.append( (x,y) )
  99.  
  100.         #tft.text( font, ".", x,y, gc9a01.color565( 10,255,10), gc9a01.color565(0,0,0) )
  101.         tft.pixel( x,y, gc9a01.color565( 0,255,0) )
  102.  
  103.         time.sleep(0.01)
  104.  
  105.  
  106. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement