10. Case 07: Smart Remote Control Musical Light¶
Level:
10.1. Sender¶
Background¶
What is the Smart Remote Control Musical Light?
Nowadays, different electronic furniture can also be controlled remotely. In this case, it illustrates the concept of remote control in Smart Home. The home owner can control the room atmosphere in the living room by pressing the remote. (Change of music and light)
Principle of Remote (Sender)
-Micro:bit includes the radio function, allowing two or more Micro:bit to form a group and communicate in a small area.
-In this case, this micro:bit sender (Remote) join group 1 with receiver. When we pressed the different button from micro:bit, it will send different message (mode) to another micro:bit so that the receiver will do the corresponding action.
-The message represent the mode which is “Funny”, “Exciting” and “Stop Music”.
Sender
Part List¶
Assembly step¶
N/A
Hardware connect¶
N/A
Programming(Makecode)¶
Step 1. Connect to radio group
In
on Start
, put aradio set group 1
to join the radio group 1
Step 2. Send message to group
Snap
on button A pressed
to editorIn
on button A pressed
, put aradio send string funny
to sendfunny
message to group 1 micro:bitsRepeat the steps with minor changes on the trigger button and string to create other message sender for
excited
andstop_music
Full Solution MakeCode: https://makecode.microbit.org/_JF0RtbVihXDD
You could also download the program from the following website:
Result¶
After loaded program to micro:bit,
When the press the button A, micro:bit sends the funny
message to group 1
.
When the press the button B, micro:bit sends the excited
message to group 1
.
When the press the button A and B, micro:bit sends the stop_music
message to group 1
.
Think¶
1. Other than press button, any other way to make the decision how to send the message?
10.2. Receiver¶
Background¶
Principle of Music and Light Player (Receiver)
When this Micro:bit receives the message from the another Micro:bit (Remote), it will use the buzzer to play a different tone or music, at the same time, the multi-color LED will be changed to have better ambience. There are 3 modes, one is enjoyable mode, another is exciting mode, the last one is Stop Music.
Part List¶
Assembly step¶
Step 1
In this case, build the “Big Style Model” as a home base.
Step 2
To build a living room, put model E1 onto model A, align with the holes at model A and B3.
Step 3
Attach the multi-color LED to the model B3 using M4*10mm screws and nuts. And the connecting wire should be bended to the hole nearby.
Step 4
To build a sofa model. Put the model K3 to the two sides of model K1.
Step 5
Put model K2 all together to the cardboard parts (K1-K3).
Step 6
The sofa completed!
Step 7
Place the sofa at the living room.
Step 8
Put the model H as a decroration display on model B3.
Step 9
Assembly completed!
Programming (MakeCode)¶
Step 1. Connect to radio group and initialize LED and music flag
Create a variable called
mode
In
on Start
, put aradio set group 1
to join the radio group 1Initialize Multi-Color LED by
set strip to NeoPixel at pin P1 with 1 leds as RGB(GRB format)
Set the variable mode value to 0 by
set mode to 0
Step 2. Examine the radio message and take action
Snap
on radio received receivedstring
block to editorPut a nested
if-else
statement inside that blockIn the first condition, use
receivedstring = stop_music
to filter out thestop_music
message, change themode
flag variable to0
In the second condition, use
receivedstring = funny
to filter out thefunny
message, change themode
flag variable to1
In the third condition, use
receivedstring = excited
to filter out theexcited
message, change themode
flag variable to2
Step 3. Make the change color function
Create two function called
rainbow
andflash
For each function, use
strip show color XXX
andpause(ms) XXX
to fill in the pattern of color changes as you want
Step 4. Change LED color by the flag
The color of LED should be change following by the flag
Flag | Meaning |
---|---|
0 | stop_music |
1 | funny |
2 | excited |
Put a nested
if-else
statement inside theForever
Use
mode = 0
as the first conditionIn the first
if
segment, that’s meansstop_music
, stop the playing sound bystop all sounds
Turn off the LED by
strip show color black
Use
mode = 1
as the second conditionIn the second
if
segment, that’s meansfunny
, stop the playing sound bystop all sounds
, then play a funny music withstart melody prelude repeating once
Execute the function to change to rainbow pattern by
call Rainbow
Use
mode = 2
as the third conditionIn the third
if
segement, that’s meansexcited
, stop the playing sound bystop all sounds
, then play a excited music withstart melody chase repeating once
Execute the function to change to flash pattern by
call flash
Full Solution MakeCode: https://makecode.microbit.org/_3PLEfo3pX5r4
You could also download the program from the following website:
Results¶
After loaded program to micro:bit,
When received the funny
message, micro:bit will play the funny music and the light will show in rainbow mode.
When received the excited
message, micro:bit will play the excited music and the light will show in flash mode.
When received the the stop_music
message, micro:bit will stop the music and turn off the light.
Think¶
Apart from the built in melody, can you make your own music melody?
Can you control other hardware like a motor fan using radio control?