-
-
Save brentru/3ad6a5b2306122e20dd57822d66845b1 to your computer and use it in GitHub Desktop.
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
# Scales the cursor up when the PyBadge/PyGamer is tapped. | |
# Scales the cursor down when the A button is clicked. | |
import time | |
import board | |
import busio | |
import digitalio | |
import displayio | |
import adafruit_lis3dh | |
from adafruit_cursorcontrol.cursorcontrol import Cursor | |
from adafruit_cursorcontrol.cursorcontrol_cursormanager import CursorManager | |
# Hardware I2C setup | |
i2c = busio.I2C(board.SCL, board.SDA) | |
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT) | |
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1) | |
# Set range of accelerometer (can be RANGE_2_G, RANGE_4_G, RANGE_8_G or RANGE_16_G). | |
lis3dh.range = adafruit_lis3dh.RANGE_8_G | |
# Set Tap Detection | |
lis3dh.set_tap(1, 60) | |
# Create the display | |
display = board.DISPLAY | |
# Create the display context | |
splash = displayio.Group(max_size=5) | |
# initialize the mouse cursor object | |
mouse_cursor = Cursor(display, display_group=splash) | |
# initialize the cursormanager | |
cursor = CursorManager(mouse_cursor) | |
# show displayio group | |
display.show(splash) | |
while True: | |
cursor.update() | |
if lis3dh.tapped: | |
print('Tapped!') | |
mouse_cursor.scale+=1 | |
if cursor.is_clicked: | |
print('click!') | |
mouse_cursor.scale-=1 | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment