19 tra Display emotion
Using the commands:
– on button A pressed,
– on button B pressed,
– on logo pressed,
– show leds,
– play sound,
create a program where the micro:bit displays a smiley face with LED lights when button A is pressed, a sad face when button B is pressed and a sleeping face when logo is touched. Also, micro:bit needs to play a sound based on the displayed mood.
1.
From the Input command group, select the on button A pressed block. All commands within this block will execute only when button A is pressed.
3.
Place the on button A pressed command again, but this time select button B from the dropdown menu. Then, within the block, add the show leds command and draw the sad face.
5.
Now, from the Music category select the play giggle until done command from the micro:bit (V2) section. Put the command after each show leds command and choose happy, sad and yawn sounds from the dropdown menu.
2.
Inside the on button A pressed block, place the show leds command and draw the smiley face.
4.
From the Input command group, select the on logo pressed block, by clicking the arrow, a dropdown menu opens, from which you select touched. Then, within the block, add the show leds command and draw the sleeping face.
Although your programs are created using Blocks, you’ll need to copy the JavaScript code of your created program for solving certain escape room tasks. After you create a program in MakeCode Blocks editor, you can see its JavaScript version by going to JavaScript mode.
Copy the JavaScript code from your Display emotion program and paste it into the box below:
This publication reflects the views only of the author, and the Commission cannot be held responsible for any use which may be made of the information contained therein.