oled_display_joystick.py

# هذا العمل مرخص بموجب ترخيص MIT.
# حقوق النشر (c) 2013-2025 لشركة OpenMV LLC. جميع الحقوق محفوظة.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# مثال شاشة OLED مع عصا التحكم (Joystick)
#
# ملاحظة: لتشغيل هذا المثال، ستحتاج إلى لوحة توسيع OLED لجهاز OpenMV AE3 الخاص بك
#
# تتيح لك لوحة توسيع 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 ""