Skip to content

Commit 7cd481c

Browse files
committed
Added clue_ams_remote.py
1 parent 828d792 commit 7cd481c

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

examples/clue_ams_remote.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""
2+
This example solicits that apple devices that provide notifications connect to it, initiates
3+
pairing, prints existing notifications and then prints any new ones as they arrive.
4+
"""
5+
6+
import time
7+
import adafruit_ble
8+
from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
9+
from adafruit_ble_apple_media import AppleMediaService
10+
from adafruit_clue import clue
11+
12+
# PyLint can't find BLERadio for some reason so special case it here.
13+
radio = adafruit_ble.BLERadio() # pylint: disable=no-member
14+
a = SolicitServicesAdvertisement()
15+
a.solicited_services.append(AppleMediaService)
16+
radio.start_advertising(a)
17+
18+
while not radio.connected:
19+
pass
20+
21+
print("connected")
22+
23+
known_notifications = set()
24+
25+
i = 0
26+
if radio.connected:
27+
for connection in radio.connections:
28+
if not connection.paired:
29+
connection.pair()
30+
print("paired")
31+
32+
ams = connection[AppleMediaService]
33+
34+
while radio.connected:
35+
if ams.playing:
36+
play = "Playing"
37+
else:
38+
play = "Paused"
39+
print("{} - {}, {}".format(ams.title, ams.artist, play))
40+
41+
# Capacitive touch pad marked 0 goes to the previous track
42+
if clue.touch_0:
43+
ams.previous_track()
44+
time.sleep(0.25)
45+
46+
# Capacitive touch pad marked 1 toggles pause/play
47+
if clue.touch_1:
48+
ams.toggle_play_pause()
49+
time.sleep(0.25)
50+
51+
# Capacitive touch pad marked 2 advances to the next track
52+
if clue.touch_2:
53+
ams.next_track()
54+
time.sleep(0.25)
55+
56+
# If button B (on the right) is pressed, it increases the volume
57+
if 'B' in clue.were_pressed:
58+
ams.volume_up()
59+
time.sleep(0.30)
60+
while 'B' in clue.were_pressed:
61+
ams.volume_up()
62+
time.sleep(0.07)
63+
64+
# If button A (on the left) is pressed, the volume decreases
65+
if 'A' in clue.were_pressed:
66+
ams.volume_down()
67+
time.sleep(0.30)
68+
while 'A' in clue.were_pressed:
69+
ams.volume_down()
70+
time.sleep(0.07)
71+
72+
print("disconnected")

0 commit comments

Comments
 (0)