oled_display_joystick.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2025 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 带摇杆的OLED显示示例
#
# 注意:运行此示例需要为您的OpenMV AE3配备OLED扩展板
#
# OLED扩展板让您可以随时随地查看OpenMV AE3的帧缓冲区。

import csi
import time
import display
from pca9674a import PCA9674A
from machine import I2C

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.VGA)
csi0.window((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(csi0.snapshot(), x=cursor_x, y=cursor_y,
              x_scale=x_scale_def, y_scale=y_scale_def)

    print(clock.fps())

results matching ""

    No results matching ""