Created
December 17, 2022 05:24
-
-
Save yswallow/f6ef67084a26dfd8375ef082562fdc47 to your computer and use it in GitHub Desktop.
Seeed Studio XIAO SAMD21/CircuitPythonでトラックポイントを使う
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import board | |
import digitalio | |
import time | |
import touchio | |
import usb_hid | |
from adafruit_hid.mouse import Mouse | |
mouse = Mouse(usb_hid.devices) | |
forward = digitalio.DigitalInOut(board.D7) | |
backward = digitalio.DigitalInOut(board.D8) | |
forward.direction = digitalio.Direction.OUTPUT | |
backward.direction = digitalio.Direction.OUTPUT | |
x = touchio.TouchIn(board.A0) | |
y = touchio.TouchIn(board.A1) | |
backward.value = True | |
forward.value = False | |
time.sleep(0.1) | |
x1 = x.raw_value | |
y1 = y.raw_value | |
backward.value = False | |
forward.value = True | |
time.sleep(0.1) | |
x2 = x.raw_value | |
y2 = y.raw_value | |
while True: | |
backward.value = True | |
forward.value = False | |
time.sleep(0.01) | |
xm = x.raw_value - x1 | |
ym = y.raw_value - y1 | |
backward.value = False | |
forward.value = True | |
time.sleep(0.01) | |
xp = x.raw_value - x2 | |
yp = y.raw_value - y2 | |
print(xm, ym, xp, yp) | |
dx = xp-xm | |
dy = yp-ym | |
rep_y = dx if dx < -16 or 16 < dx else 0 | |
rep_x = -dy if dy < -16 or 16 < dy else 0 | |
mouse.move(int(rep_x/4), int(rep_y/4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment