笑脸按钮活动

让我们 通过这个活动来学习如何发送和接收数据吧!

  • Get started
  • MakeCode
  • Radio
Print lesson
  • 年龄 8+
  • 30 分钟
  • MakeCode Editor

简介

这个项目介绍了micro:bit的数据发送到和接收。

教学指南

打开 打开 teacher resources

课堂活动

7个步骤

第一步

Drag an on button pressed block into the workspace; this will run code when button A is pressed.


input.onButtonPressed(Button.A, function () {
  
})
          

第二步

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(`
        . # . # .
        . . . . .
        . . . . .
        # . . . #
        . # # # .
        `)
})
          

第三步

点击Download(下载)将代码下载到你的micro:bit并试着按下按钮A

第四步

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(`
        . # . # .
        . . . . .
        . . . . .
        . # # # .
        # . . . #
        `)
})
          

第五步

点击 Download(下载)将代码下载到你的micro:bit并试着按下按钮A或B。

第六步

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(`
        . . # . #
        . . . . .
        . . . . .
        # . . . #
        . # # # .
        `)
})
          

第七步

点击 Download(下载)将代码下载到你的micro:bit并将它显示给你的朋友们吧!

挑战

试着添加下列功能:

  • 将一个写好的信息发送到第二块micro:bit。
  • 允许用户选择一张图片并将它发送到第二块micro:bit
  • 允许第三块micro:bit发送和接收数据

了解更多

“剪刀石头布”活动将教你如何用micro:bit制作一个炫酷的游戏哦!

Selecting this opens external content from our support system, which adheres to their privacy policy.