Smiley Buttons Activity
Learn how to send and receive data in this activity!
Bevezetés
This project introduces sending and receiving data to and from micro:bits.
Teacher Guide
Activity
Step One
Drag an on button pressed block into the workspace; this will run code when button A is pressed.
input.onButtonPressed(Button.A, function () {
})
Step Two
Place a show leds block inside the on button pressed block to display a smiley on the screen when A is pressed. Click the squares so they are filled white; this represents an 'on' LED. Use this to draw a face.
input.onButtonPressed(Button.A, function () {
basic.showLeds(`
. # . # .
. . . . .
. . . . .
# . . . #
. # # # .
`)
})
Step Three
Click Download to transfer your code in your micro:bit and try pressing button A.
Step Four
Repeat the previous steps with Button B; add on button pressed, click the arrow next to 'A' to change to button B, and show leds blocks to display a frown when button B is pressed.
input.onButtonPressed(Button.B, function () {
basic.showLeds(`
. # . # .
. . . . .
. . . . .
. # # # .
# . . . #
`)
})
Step Five
Click Download to transfer your code in your micro:bit and try pressing button A or B.
Step Six
Add a secret mode where A and B are pressed together (drag another 'on button pressed' block and click the arrow next to 'A' to change to 'A+B'). In that case, add multiple show leds blocks to create an animation...
input.onButtonPressed(Button.AB, function () {
basic.showLeds(`
# . # . .
. . . . .
. . . . .
# . . . #
. # # # .
`)
basic.showLeds(`
. . # . #
. . . . .
. . . . .
# . . . #
. # # # .
`)
})
Step Seven
Click Download to transfer your code in your micro:bit and show it off to your friends!
Challenge
Try to add the following functionality:
- Send a written message to the second micro:bit.
- Allow the user to choose a picture and send it to the second micro:bit
- Allow a third micro:bit to send and receive data
Learn More
The 'Rock Paper Scissors' activity teaches you how to make a cool game for the micro:bit!