Created
June 19, 2022 18:54
-
-
Save DerBroader71/976f314d0d30d960968396e8d5888023 to your computer and use it in GitHub Desktop.
Mouse Jiggler with CircuitPython (Adafruit Trinkey QT2040) with enable/disable
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 neopixel | |
import usb_hid | |
import touchio | |
import time | |
from time import sleep | |
from adafruit_hid.mouse import Mouse | |
from random import randint | |
HOW_LONG = 10 # How long between jiggles in seconds | |
ENABLED = False | |
LAST_TIME = -1 | |
RAND_SLEEP = -1 | |
mouse = Mouse(usb_hid.devices) | |
pixels = neopixel.NeoPixel(board.NEOPIXEL, 4, auto_write=False) | |
pixels.brightness = 0.01 | |
touch1 = touchio.TouchIn(board.TOUCH1) | |
touch2 = touchio.TouchIn(board.TOUCH2) | |
def green(): | |
pixels.fill((0, 255, 0)) | |
pixels.show() | |
sleep(0.1) | |
def blue(): | |
pixels.fill((0, 0, 255)) | |
pixels.show() | |
sleep(0.1) | |
def jiggle(): | |
for each in range(randint(1, 4)): | |
x = randint(1, 50) | |
y = randint(1, 50) | |
mouse.move(x, y) | |
mouse.move(-x, -y) | |
blue() | |
while True: | |
now = time.monotonic() | |
# detect if button has been pressed to enable jiggle function | |
if touch1.value and touch2.value: | |
ENABLED = not ENABLED | |
sleep(0.1) | |
if ENABLED and now <= LAST_TIME + RAND_SLEEP: | |
green() | |
if ENABLED and now >= LAST_TIME + RAND_SLEEP: | |
jiggle() | |
RAND_SLEEP = randint(1, HOW_LONG) | |
LAST_TIME = now | |
if not ENABLED: | |
blue() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment