Skip to content
Snippets Groups Projects
Verified Commit 2ce3e9ff authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Add comments to LED cheese example

parent 8cdab984
No related branches found
No related tags found
No related merge requests found
......@@ -21,9 +21,11 @@ from wifi import Wifi
from mytrix import Matrix
def set_colour(matches, event):
"""Set the RGB LED colour depending on the colour name in a message."""
colour = matches.group(1).lower().strip()
sender = event["sender"]
# Mapping colour names to RGB values
colour_map = {
"schwarz": (0,0,0),
"blau": (0,0,255),
......@@ -39,9 +41,11 @@ def set_colour(matches, event):
if is_allowed(sender):
if not colour in colour_map:
# The colour name is not in the mapping
matrix.send_room_message(ROOM_ID, "Diese Farbe kenne ich leider nicht, %s :(." % (sender,))
return
# Map to red, blue and green values, and set PWM duty (scaled from 256 to 1024)
r, g, b = colour_map[colour]
led_red.duty(r*4)
led_green.duty(g*4)
......@@ -50,6 +54,7 @@ def set_colour(matches, event):
matrix.send_room_message(ROOM_ID, "Ich leuchte jetzt %s, %s!" % (colour, sender))
def is_allowed(sender):
"""Check whether a sender is allowed to control the cheese."""
with open("users.txt", "rt") as f:
users = f.readlines()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment