Day 14

Remote Control Christmas Ornaments

Submitted by Jacqueline Russell (from the Microsoft MakeCode Team)

Bling up your Christmas tree

Bling up your Christmas tree this season with blinky micro:bit and/or Circuit Playground Express ornaments that you can control remotely! This is an easy and fun DIY project that should take no more than an hour or two to do with your kids.

Materials:

· 2 or more micro:bits or Circuit Playground Express boards

· USB cable

· Battery packs and batteries to go with each micro:bit or Circuit Playground Express

· Ornament hangers or paper clips

· Colored construction paper or regular paper (thicker is better)

· Scissors

· Tape

· Colored markers

· Glitter, jewels, or other decorations

Make

Draw and cut out fun ornament shapes from colored paper.

Tape your micro:bit or Circuit Playground Express boards to the front of the paper shapes using a loop of tape to make it double-sided.

Tape the battery packs onto the back (try to hide the battery wire).

Poke a small hole in the ornament paper, and insert the ornament hanger or paper clip.

Code

Gather together as many micro:bits or Circuit Playground Expresses as you can. You’ll need at least 2 – one for the sender and one for the receiver.

Micro:bit

Open up a browser to https://makecode.microbit.org and create a New Project. Name this project “OrnamentReceiver”.

From the Radio Toolbox drawer, drag out a Radio Set Group block, and drop into the On Start block. This sets the radio frequency or channel across which our micro:bits will communicate.

Now we need some variables to tell us what animation to play. In this project, we’ll make two different animations – a heart animation and a snowflake animation.

From the Variables Toolbox drawer, click on the Make a Variable button to create two variables – name them Heart and Snowflake.

Now let’s create our animations. From the Logic Toolbox drawer, drag an If Then Else block to the Workspace and drop into the Forever loop.

Press the Plus icon (‘+’) on the If Then Else block to create an Else If clause. Then click the Minus icon (‘– ‘) next to the Else clause to delete it.

From the Variables Toolbox drawer, drag a Heart variable block into the If Then clause replacing the default value of true. From the Variables Toolbox drawer, drag a Snowflake variable block into the Else If clause.


From the Basic Toolbox drawer, drag some Show Icon and Show LED blocks onto the Workspace and place them into the If Then block for our Heart animation, and the Else If block for the Snowflake animation

From the Radio Toolbox drawer, drag out an On Radio Received receivedNumber block and drop onto the Workspace

From the Logic Toolbox drawer, drag an If Then Else block to the Workspace and drop into the On Radio Received receivedNumber block.

From the Logic Toolbox drawer, under the Comparison section, drag an Equals comparison block to the Workspace and drop into the If Then clause replacing the default ‘true’.

From the Variables Toolbox drawer, drag a receivedNumber variable block onto the Workspace and drop into the first slot of the Equals comparison block. Type a 1 into the second slot of the Equals comparison block.

From the Variables Toolbox drawer, drag two Set variable blocks onto the Workspace and drop them into the If Then block. Use the drop-down menu to set one to Heart and one to Snowflake.

From the Logic Toolbox drawer, scroll down to drag one True and one False value block onto the Workspace and drop one each into the Set variable blocks.

Right-click on these Set variable blocks and select Duplicate to make copies of both of them and drag them into the Else clause. Use the drop-down menus in the True and False blocks to set the opposite value.

Download this code onto all your Ornament Receiver micro:bits. For the micro:bit which will act as the remote control, you will just need to program it to send the number 1 or the number 2 to switch animations. Complete code below:

Ornament Receiver – https://makecode.microbit.org/_eCqWCDX046DT

Circuit Playground Version

For the sake of space on this page we have included the Word Document that takes you through all the steps above as well as directions to do this same project using Circuit Playground. Please enjoy and show us your ornament creations!

Remote Control Xmas Ornaments.docx