Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Μ
µtrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Teckids
Projekt Hack-n-Fun
Libs
µtrix
Commits
2ce3e9ff
Verified
Commit
2ce3e9ff
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Add comments to LED cheese example
parent
8cdab984
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/led_cheese.py
+5
-0
5 additions, 0 deletions
examples/led_cheese.py
with
5 additions
and
0 deletions
examples/led_cheese.py
+
5
−
0
View file @
2ce3e9ff
...
...
@@ -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
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment