embeded/rpi pico
rpi pico, circuit python, HW-504를 이용하여 빨콩 만들기
구차니
2025. 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]