Skip to content

Commit 542281c

Browse files
authored
Merge pull request #1570 from kattni/slider-trinkey
Adding Slider demos.
2 parents 7e1b71e + 95c6231 commit 542281c

File tree

5 files changed

+144
-0
lines changed

5 files changed

+144
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""CircuitPython capacitive touch example for Slider Trinkey"""
2+
import time
3+
import board
4+
import touchio
5+
6+
touch = touchio.TouchIn(board.TOUCH)
7+
8+
while True:
9+
if touch.value:
10+
print("Pad touched!")
11+
time.sleep(0.1)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""
2+
Slider Trinkey Hue Brightness Python Example
3+
(Requires Hue and Monitor Brightness CircuitPython example to be running on the Slider Trinkey)
4+
"""
5+
import sys
6+
from phue import Bridge
7+
import serial
8+
from serial.tools import list_ports
9+
10+
# Update this to the room, zone or individual lamp you want to control.
11+
LAMP_OR_GROUP_NAME = "Office"
12+
13+
# Update this to the IP address of your Hue Bridge.
14+
b = Bridge("0.0.0.0")
15+
16+
slider_trinkey_port = None
17+
ports = list_ports.comports(include_links=False)
18+
for p in ports:
19+
if p.pid is not None:
20+
print("Port:", p.device, "-", hex(p.pid), end="\t")
21+
if p.pid == 0x8102:
22+
slider_trinkey_port = p
23+
print("Found Slider Trinkey!")
24+
trinkey = serial.Serial(p.device)
25+
break
26+
else:
27+
print("Did not find Slider Trinkey port :(")
28+
sys.exit()
29+
30+
# If the app is not registered and the button on the Hue Bridge is not pressed, press the button
31+
# and call connect() (this only needs to be run a single time)
32+
b.connect()
33+
b.get_api()
34+
35+
is_group = False
36+
light = None
37+
38+
# First, check if it's a group name.
39+
for group_data in b.get_group().values():
40+
if group_data["name"] == LAMP_OR_GROUP_NAME:
41+
print("Found group with name", LAMP_OR_GROUP_NAME)
42+
is_group = True
43+
44+
# If it's not a group, find the lamp by name.
45+
if not is_group:
46+
light_names = b.get_light_objects("name")
47+
light = light_names[LAMP_OR_GROUP_NAME]
48+
print("Found light with name", LAMP_OR_GROUP_NAME)
49+
50+
current_brightness = None
51+
while True:
52+
x = trinkey.readline().decode("utf-8")
53+
if not x.startswith("Slider: "):
54+
continue
55+
56+
# Convert the Slider Trinkey output value of 0-100 to 0-254.
57+
brightness_value = int((float(x.split(": ")[1]) / 100) * 254)
58+
59+
if current_brightness is None or brightness_value != current_brightness:
60+
print("Setting brightness to:", brightness_value)
61+
if is_group:
62+
b.set_group(LAMP_OR_GROUP_NAME, {"bri": brightness_value})
63+
else:
64+
light.brightness = brightness_value
65+
current_brightness = brightness_value
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import time
2+
import board
3+
from analogio import AnalogIn
4+
import adafruit_simplemath
5+
6+
analog_in = AnalogIn(board.POTENTIOMETER)
7+
8+
9+
def read_pot(samples, min_val, max_val):
10+
sum_samples = 0
11+
for _ in range(samples):
12+
sum_samples += analog_in.value
13+
sum_samples /= samples # ok take the average
14+
15+
return adafruit_simplemath.map_range(sum_samples, 100, 65535, min_val, max_val)
16+
17+
18+
while True:
19+
print("Slider:", round(read_pot(10, 0, 100)))
20+
time.sleep(0.1)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Slider Trinkey Monitor Brightness Demo for Windows
3+
(Requires Hue and Monitor Brightness CircuitPython example to be running on the Slider Trinkey)
4+
"""
5+
import sys
6+
import screen_brightness_control as sbc
7+
import serial
8+
from serial.tools import list_ports
9+
10+
slider_trinkey_port = None
11+
ports = list_ports.comports(include_links=False)
12+
for p in ports:
13+
if p.pid is not None:
14+
print("Port:", p.device, "-", hex(p.pid), end="\t")
15+
if p.pid == 0x8102:
16+
slider_trinkey_port = p
17+
print("Found Slider Trinkey!")
18+
trinkey = serial.Serial(p.device)
19+
break
20+
else:
21+
print("Did not find Slider Trinkey port :(")
22+
sys.exit()
23+
24+
curr_brightness = sbc.get_brightness()
25+
26+
while True:
27+
x = trinkey.readline().decode('utf-8')
28+
if not x.startswith("Slider: "):
29+
continue
30+
31+
val = int(float(x.split(": ")[1]))
32+
33+
if val != curr_brightness:
34+
print("Setting brightness to:", val)
35+
sbc.set_brightness(val)
36+
curr_brightness = sbc.get_brightness()

Slider_Trinkey/NeoPixel_Blink/code.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""CircuitPython NeoPixel Blink Example for Slider Trinkey"""
2+
import time
3+
import board
4+
import neopixel
5+
6+
pixel = neopixel.NeoPixel(board.NEOPIXEL, 2)
7+
8+
while True:
9+
pixel.fill((255, 0, 0))
10+
time.sleep(0.5)
11+
pixel.fill((0, 0, 0))
12+
time.sleep(0.5)

0 commit comments

Comments
 (0)