Skip to content

Adding Slider demos. #1570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Slider_Trinkey/Capacitive_Touch/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""CircuitPython capacitive touch example for Slider Trinkey"""
import time
import board
import touchio

touch = touchio.TouchIn(board.TOUCH)

while True:
if touch.value:
print("Pad touched!")
time.sleep(0.1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""
Slider Trinkey Hue Brightness Python Example
(Requires Hue and Monitor Brightness CircuitPython example to be running on the Slider Trinkey)
"""
import sys
from phue import Bridge
import serial
from serial.tools import list_ports

# Update this to the room, zone or individual lamp you want to control.
LAMP_OR_GROUP_NAME = "Office"

# Update this to the IP address of your Hue Bridge.
b = Bridge("0.0.0.0")

slider_trinkey_port = None
ports = list_ports.comports(include_links=False)
for p in ports:
if p.pid is not None:
print("Port:", p.device, "-", hex(p.pid), end="\t")
if p.pid == 0x8102:
slider_trinkey_port = p
print("Found Slider Trinkey!")
trinkey = serial.Serial(p.device)
break
else:
print("Did not find Slider Trinkey port :(")
sys.exit()

# If the app is not registered and the button on the Hue Bridge is not pressed, press the button
# and call connect() (this only needs to be run a single time)
b.connect()
b.get_api()

is_group = False
light = None

# First, check if it's a group name.
for group_data in b.get_group().values():
if group_data["name"] == LAMP_OR_GROUP_NAME:
print("Found group with name", LAMP_OR_GROUP_NAME)
is_group = True

# If it's not a group, find the lamp by name.
if not is_group:
light_names = b.get_light_objects("name")
light = light_names[LAMP_OR_GROUP_NAME]
print("Found light with name", LAMP_OR_GROUP_NAME)

current_brightness = None
while True:
x = trinkey.readline().decode("utf-8")
if not x.startswith("Slider: "):
continue

# Convert the Slider Trinkey output value of 0-100 to 0-254.
brightness_value = int((float(x.split(": ")[1]) / 100) * 254)

if current_brightness is None or brightness_value != current_brightness:
print("Setting brightness to:", brightness_value)
if is_group:
b.set_group(LAMP_OR_GROUP_NAME, {"bri": brightness_value})
else:
light.brightness = brightness_value
current_brightness = brightness_value
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import time
import board
from analogio import AnalogIn
import adafruit_simplemath

analog_in = AnalogIn(board.POTENTIOMETER)


def read_pot(samples, min_val, max_val):
sum_samples = 0
for _ in range(samples):
sum_samples += analog_in.value
sum_samples /= samples # ok take the average

return adafruit_simplemath.map_range(sum_samples, 100, 65535, min_val, max_val)


while True:
print("Slider:", round(read_pot(10, 0, 100)))
time.sleep(0.1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
Slider Trinkey Monitor Brightness Demo for Windows
(Requires Hue and Monitor Brightness CircuitPython example to be running on the Slider Trinkey)
"""
import sys
import screen_brightness_control as sbc
import serial
from serial.tools import list_ports

slider_trinkey_port = None
ports = list_ports.comports(include_links=False)
for p in ports:
if p.pid is not None:
print("Port:", p.device, "-", hex(p.pid), end="\t")
if p.pid == 0x8102:
slider_trinkey_port = p
print("Found Slider Trinkey!")
trinkey = serial.Serial(p.device)
break
else:
print("Did not find Slider Trinkey port :(")
sys.exit()

curr_brightness = sbc.get_brightness()

while True:
x = trinkey.readline().decode('utf-8')
if not x.startswith("Slider: "):
continue

val = int(float(x.split(": ")[1]))

if val != curr_brightness:
print("Setting brightness to:", val)
sbc.set_brightness(val)
curr_brightness = sbc.get_brightness()
12 changes: 12 additions & 0 deletions Slider_Trinkey/NeoPixel_Blink/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""CircuitPython NeoPixel Blink Example for Slider Trinkey"""
import time
import board
import neopixel

pixel = neopixel.NeoPixel(board.NEOPIXEL, 2)

while True:
pixel.fill((255, 0, 0))
time.sleep(0.5)
pixel.fill((0, 0, 0))
time.sleep(0.5)