-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.py
47 lines (36 loc) · 1.06 KB
/
code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import time
import usb_hid
from adafruit_hid.mouse import Mouse
import os
# For LED control
import board
import pwmio
led = pwmio.PWMOut(board.GP22, frequency=5000, duty_cycle=65535)
mouse = Mouse(usb_hid.devices)
wait = os.getenv("MOVE_INTERVAL") / 1000
move_distance = os.getenv("MOVE_STEP")
mouse_moving = os.getenv("MOVE_MOVING")
state = 0
blink_interval = 0.05
print("Mouse mover started")
while mouse_moving:
if state == 0:
x, y = move_distance, move_distance
move_name = "UP_RIGHT"
elif state == 1:
x, y = move_distance, -move_distance
move_name = "DOWN_RIGHT"
elif state == 2:
x, y = -move_distance, -move_distance
move_name = "DOWN_LEFT"
elif state == 3:
x, y = -move_distance, move_distance
move_name = "UP_LEFT"
led.duty_cycle = 63000
mouse.move(x=x, y=y)
print(f"Mouse did {move_name} with coordinates ({x}, {y})")
time.sleep(blink_interval)
led.duty_cycle = 65000
time.sleep(wait - blink_interval)
state = (state + 1) % 4
print("Mouse mover stopped")