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

Implement actual colours and LED lighting in LED cheese example

parent 4d84f524
No related branches found
No related tags found
No related merge requests found
......@@ -15,17 +15,39 @@
import re
import time
from machine import Pin, deepsleep
from machine import Pin, PWM
from credentials import *
from wifi import Wifi
from mytrix import Matrix
def set_colour(matches, event):
colour = matches.group(1)
colour = matches.group(1).lower().strip()
sender = event["sender"]
colour_map = {
"schwarz": (0,0,0),
"blau": (0,0,255),
"rot": (255,0,0),
"gruen": (0,255,0),
"tuerkis": (0,255,255),
"lila": (139,0,139),
"orange": (255,140,0),
"pink": (255,105,180),
"rosa": (255,0,255),
"weiss": (255,255,255),
}
if is_allowed(sender):
matrix.send_room_message(ROOM_ID, "Ich habe noch keine LEDs :(...")
if not colour in colour_map:
matrix.send_room_message(ROOM_ID, "Diese Farbe kenne ich leider nicht, %s :(." % (sender,))
return
r, g, b = colour_map[colour]
led_red.duty(r*4)
led_green.duty(g*4)
led_blue.duty(b*4)
matrix.send_room_message(ROOM_ID, "Ich leuchte jetzt %s, %s!" % (colour, sender))
def is_allowed(sender):
with open("users.txt", "rt") as f:
......@@ -47,15 +69,13 @@ def allow_user(matches, event):
f.write(user + "\n")
matrix.send_room_message(ROOM_ID, "%s darf mich jetzt leuchten lassen!" % (user,))
# Define LED colour pins
# Define LED colour pins and PWM objects
pin_red = Pin(13, Pin.OUT)
pin_green = Pin(12, Pin.OUT)
pin_blue = Pin(14, Pin.OUT)
# Switch off all LEDs
pin_red.off()
pin_green.off()
pin_blue.off()
led_red = PWM(pin_red, 5000)
led_green = PWM(pin_green, 5000)
led_blue = PWM(pin_blue, 5000)
# Connect to wifi
network = Wifi(SSID, PSK)
......
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