Example: 50-OpenMV-Boards/52-Alif-Boards/51-OLED-Shield/oled_display_joystick.py
import sensor
import time
import display
from pca9674a import PCA9674A
from machine import I2C
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.VGA)
sensor.set_windowing((400, 400))
lcd = display.SPIDisplay(width=128, height=128, controller=display.SSD1351())
clock = time.clock()
def read_expander(pin):
global exp, state
state = exp.read() ^ 0xFF
x_scale_def = 128 / 400
y_scale_def = 128 / 400
state = 0
cursor_x = 0
cursor_y = 0
exp = PCA9674A(I2C(1), irq_pin="P9", callback=read_expander)
def update_cursor():
global cursor_x, cursor_y
if state & 0x01:
cursor_x += 2
if state & 0x02:
cursor_y -= 2
if state & 0x04:
cursor_x -= 2
if state & 0x08:
cursor_y += 2
if state & 0x10:
cursor_x = 0
cursor_y = 0
while True:
clock.tick()
update_cursor()
lcd.write(sensor.snapshot(), x=cursor_x, y=cursor_y,
x_scale=x_scale_def, y_scale=y_scale_def)
print(clock.fps())