Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # gc9a01_test.py -- fakey lissajous in Micropython
- # 21 Oct 2023 - @todbot / Tod Kurt
- # Uses Micropython UF2 from https://github.com/russhughes/gc9a01_mpy
- # but it seems pretty unstable, wiping out the entire flash contents
- # and requiring a reinstall of Micropython.
- # And the font mpy files provided do not work with the provided UF2.
- #
- # Cirque 40mm touchpad code added. -Ticktok
- # Requires Adafruit Blinka library to use circuitpython libraries with micropython
- # https://learn.adafruit.com/circuitpython-libraries-on-micropython-using-the-raspberry-pi-pico/installing-blinka-and-libraries
- # Requires Cirque touchpad circuitpython library.
- # https://github.com/2bndy5/CircuitPython_Cirque_Pinnacle
- #micropython libraries for gc9ao1
- import random, math, time
- from machine import Pin, SPI
- import gc9a01
- #import vga1_bold_16x32 as font #Need to find a non .mpy version as micropython doesn't support mpy libraries.
- #circuitpython libraries for trackpad
- import board
- import busio
- from digitalio import DigitalInOut
- import circuitpython_cirque_pinnacle.glidepoint as Pinnacle
- def mapRange(value, inMin, inMax, outMin, outMax):
- return int(outMin + (((value - inMin) / (inMax - inMin)) * (outMax - outMin)))
- def draw_dot(tft, x,y,c):
- tft.pixel( x,y, c )
- tft.pixel( x+1, y-1, c )
- tft.pixel( x+1, y+1, c )
- tft.pixel( x-1, y+0, c )
- tft.pixel( x+1, y-1, c )
- def main():
- dr_pin = DigitalInOut(board.GP11)
- ss_pin = DigitalInOut(board.GP13)
- sck_pin = board.GP14
- mosi_pin = board.GP15
- miso_pin = board.GP12
- cirque_spi = busio.SPI(clock=sck_pin, MISO=miso_pin, MOSI=mosi_pin)
- tpad = Pinnacle.PinnacleTouchSPI(cirque_spi, ss_pin, dr_pin=dr_pin)
- tpad.data_mode = Pinnacle.ABSOLUTE
- spi = SPI(1, baudrate=60_000_000, sck=Pin(14), mosi=Pin(15))
- tft = gc9a01.GC9A01(
- spi,
- 240,
- 240,
- reset=Pin(8, Pin.OUT),
- cs=Pin(9, Pin.OUT),
- dc=Pin(10, Pin.OUT),
- rotation=1) # 2 == 180 degrees, because of course it does
- tft.init()
- x,y = 0,0
- r = 60
- phi = 0
- tft.fill(0)
- num_trails = 10
- trails = []
- while True:
- data = tpad.report()
- # erase oldest trail element
- if len(trails) > num_trails:
- #print("hit num_trails:", x,y)
- xe,ye = trails.pop(0) # remove oldest element
- #tft.text( font, "!", xe,ye, gc9a01.color565( 0,0,0), gc9a01.color565(0,0,0) )
- tft.pixel( xe,ye, gc9a01.color565( 0,0,0) )
- # draw trail
- for (xt,yt) in trails:
- #print(x,y)
- #tft.text( font, "!", xt,yt, gc9a01.color565( 100,100,0), gc9a01.color565(0,0,0) )
- tft.pixel( xt,yt, gc9a01.color565( 100,100,0) )
- if data is None:
- # get new position
- phi += 0.05
- x = 120 + int(r * math.sin( phi ))
- y = 120 + int(r * math.cos( phi ))
- else:
- x = mapRange(data[1],0,1900,0,255)
- y = mapRange(data[2],0,1900,0,255)
- print(f"x:{x} y:{y}")
- trails.append( (x,y) )
- #tft.text( font, ".", x,y, gc9a01.color565( 10,255,10), gc9a01.color565(0,0,0) )
- tft.pixel( x,y, gc9a01.color565( 0,255,0) )
- time.sleep(0.01)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement