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
52b467b6
Verified
Commit
52b467b6
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Optionally support mmllib to play music in LED cheese example
parent
febe50b4
No related branches found
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
+19
-0
19 additions, 0 deletions
examples/led_cheese.py
with
19 additions
and
0 deletions
examples/led_cheese.py
+
19
−
0
View file @
52b467b6
...
...
@@ -22,6 +22,11 @@ from wifi import Wifi
from
mytrix
import
Matrix
from
random
import
getrandbits
try
:
from
mmllib.esp
import
play
from
mmllib.mml
import
mml
except
ImportError
:
mml
=
None
def
set_colour
(
matches
,
event
):
"""
Set the RGB LED colour depending on the colour name in a message.
"""
...
...
@@ -102,6 +107,16 @@ def off(matches, event):
matrix
.
send_room_message
(
ROOM_ID
,
"
Nerv ich? Na gut...
"
)
set_leds
(
0
,
0
,
0
)
def
music
(
matches
,
event
):
"""
Play MML music.
"""
sender
=
event
[
"
sender
"
]
if
is_allowed
(
sender
):
if
mml
is
not
None
:
matrix
.
send_room_message
(
ROOM_ID
,
"
La la la...
"
)
play
(
mml
(
matches
.
group
(
1
)),
pin_buzzer
)
else
:
matrix
.
send_room_message
(
ROOM_ID
,
"
Ich kann nicht singen :(, %s...
"
%
(
sender
,))
def
fallback
(
matches
,
event
):
"""
Fallback fo unknown messages.
"""
sender
=
event
[
"
sender
"
]
...
...
@@ -130,6 +145,9 @@ led_red = PWM(pin_red, 5000)
led_green
=
PWM
(
pin_green
,
5000
)
led_blue
=
PWM
(
pin_blue
,
5000
)
# Define buzzer pin number
pin_buzzer
=
2
# Connect to wifi
network
=
Wifi
(
SSID
,
PSK
)
network
.
connect
()
...
...
@@ -142,6 +160,7 @@ cases = OrderedDict()
cases
[
"
^%s, leuchte (.*)
"
%
(
NICK
,)]
=
set_colour
cases
[
"
^%s, hoer auf (.*)
"
%
(
NICK
,)]
=
allow_user
cases
[
"
^%s, aus
"
%
(
NICK
,)]
=
off
cases
[
"
^%s, spiele (.*)
"
%
(
NICK
,)]
=
music
cases
[
"
bloeder kaese
"
]
=
not_stupid
cases
[
"
kaeseparty
"
]
=
party
cases
[
"
^%s.*
"
%
(
NICK
,)]
=
fallback
...
...
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