Skip to content

活动

Which way now?

初学者 | MakeCode, Python | LED显示器, 加速计 | 变量 , 性能工具, 选择, 随机化

第 1 步:制作

它是什么?

Shake your micro:bit and be given a random direction to walk. You will learn about variables, and using random numbers, selection and comparison logic blocks.

这两个视频向你展示了你将制作什么以及如何编程

介绍

编程指南

工作原理

  • The program uses a variable called “direction” to store a random number.
  • Variables store numbers or values that can change in a computer program.
  • Shake the micro:bit to set “direction” to a random number between one and three.
  • The program then uses selection and comparison logic blocks to test the value of the variable.
  • If “direction” is equal to 1, then an arrow pointing north shows on the micro:bit’s LED display. If “direction” is equal to 2, then the arrow points east. Otherwise, the arrow points west.
  • To make the battery last longer, the program pauses for half a second after the arrow appears then clears the screen.

所需材料

  • micro:bit或者是MakeCode模拟器
  • MakeCode编辑器
  • battery pack (optional but recommended)
  • our set-up guide may be useful

第 2 步:编程

第3步:完善

  • Add more directions.
  • Use buttons to show icons for skipping, running, and jumping.
  • Combine with the touch stopwatch program to make a motivational tool to use in sports lessons.

Thanks to David Hay, an educator in Alberta, Canada for sharing this brilliant project idea with us.