Created
March 5, 2025 21:35
-
-
Save joeycastillo/14e61f72f8038932ddb9c9cfea490875 to your computer and use it in GitHub Desktop.
Gesture based music control using Adafruit Clue
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 time | |
import adafruit_ble | |
from adafruit_ble.advertising.standard import SolicitServicesAdvertisement | |
from adafruit_ble_apple_media import AppleMediaService | |
from adafruit_ble_apple_media import UnsupportedCommand | |
from adafruit_clue import clue | |
# Set up Bluetooth | |
radio = adafruit_ble.BLERadio() | |
radio.name = "RENAME ME" | |
advertisement = SolicitServicesAdvertisement() | |
advertisement.solicited_services.append(AppleMediaService) | |
radio.start_advertising(advertisement) | |
# Set up display | |
clue_data = clue.simple_text_display(title="My Music", title_scale=2, text_scale=2, colors=(clue.CYAN,)) | |
clue_data.show() | |
while True: | |
if not radio.connected: | |
clue_data[0].text = "Please connect to" | |
clue_data[1].text = radio.name | |
clue_data[2].text = "in Bluefruit Connect" | |
while not radio.connected: | |
pass | |
# We're connected! | |
clue_data[0].text = "Connected to" | |
clue_data[2].text = "" | |
while radio.connected: | |
for connection in radio.connections: | |
try: | |
if not connection.paired: | |
connection.pair() | |
music = connection[AppleMediaService] | |
except (RuntimeError, UnsupportedCommand, AttributeError): | |
continue | |
clue_data[0].text = music.title or "" | |
clue_data[1].text = music.album or "" | |
clue_data[2].text = music.artist or "" | |
# Gesture interface: | |
gesture = clue.gesture | |
if gesture == 1: | |
# 1 is UP | |
music.volume_up() | |
if gesture == 2: | |
# 2 is DOWN | |
music.volume_down() | |
if gesture == 3: | |
# 3 is RIGHT to LEFT | |
music.previous_track() | |
if gesture == 4: | |
# 4 is LEFT to RIGHT | |
music.next_track() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment