embeded/rpi pico2025. 8. 2. 15:57

조이스틱인데 이걸 이용해 빨콩을 만들어 봄

divider와 막판에 세제곱 하는걸 어떻게 건드리면

적절하게 최소 움직임과 빠른 움직임을 잡을수 있을 것 같은데 좋은 아이디어가 안나네..

 

 

import board
import digitalio
import analogio
import time
import usb_hid
from adafruit_hid.mouse import Mouse

adc_x = analogio.AnalogIn(board.A0)
adc_y = analogio.AnalogIn(board.A1)

click = digitalio.DigitalInOut(board.GP22)
click.direction = digitalio.Direction.INPUT
click.pull = digitalio.Pull.UP

mouse = Mouse(usb_hid.devices)

divider = 256 * 16
thres = 0 # degree
last_btn = True

calib_x = 0;
calib_y = 0;

for i in range(10):
    calib_x += adc_x.value
    calib_y += adc_y.value
    
calib_x = int(calib_x / 10)
calib_y = int(calib_y / 10)

thres_x = int(calib_x * thres / 90)
thres_y = int(calib_y * thres / 90)

print("calib : ",calib_x,",",calib_y)
print("thres : ",thres_x,",",thres_y)

while True:
#    print(adc_x.value,",",adc_y.value," ",click.value)

    if(last_btn != click.value):
        last_btn = click.value
        if last_btn is False:
            mouse.press(Mouse.LEFT_BUTTON)
            time.sleep(0.2)  # Debounce delay
        else:
            mouse.release(Mouse.LEFT_BUTTON)
            time.sleep(0.2)  # Debounce delay
    
    if adc_x.value > calib_x + thres_x:
        step = int(((adc_x.value - (calib_x + thres_x))) / divider)
        if abs(step) > 0:
            mouse.move(x = step * step * step);
        
    if adc_x.value < calib_x - thres_x:
        step = int(((adc_x.value - (calib_x - thres_x))) / divider)
        if abs(step) > 0:
            mouse.move(x = (step * step * step));

    if adc_y.value > calib_y + thres_y:
        step = int(((adc_y.value - (calib_y + thres_y))) / divider)
        if abs(step) > 0:
            mouse.move(y = step * step * step);
        
    if adc_y.value < calib_y - thres_y:
        step = int(((adc_y.value - (calib_y - thres_y))) / divider)
        if abs(step) > 0:
            mouse.move(y = (step * step * step));

 

일단은 내가 구매한 녀석이 이상해서, Y 축에 대해 점퍼를 날려주어야 정상적으로 값이 변화된다.

2025.08.02 - [잡동사니] - HW-504 이상해..

[링크 : http://chipgu.ru/viewtopic.php?t=3764&start=100]

 

요건 adafruit usb mouse 라이브러리 설명

[링크 : https://learn.adafruit.com/circuitpython-essentials/circuitpython-hid-keyboard-and-mouse]

'embeded > rpi pico' 카테고리의 다른 글

rpi pico circuit python 에서 code 실행하기  (0) 2025.08.02
rpi pico sdk  (0) 2025.03.23
rpi pico usb joystick  (0) 2024.10.07
pico real plus 윈도우에 연결하기  (0) 2024.07.31
pico real plus for U+ 구매  (0) 2024.07.28
Posted by 구차니