Example Code for micro:bit-Yacht
This routine uses micro:bit wireless communication to simulate the yacht game. It generates random numbers by detecting vibration, displays them incrementally on the LED dot matrix, and sends them to other main boards for comparison.
Hardware Preparation
- [DFR0536]GamePad for microbit (V2.0) ×2
- micro:bit ×2
Software Preparation
- MakeCode programming platform address: https://makecode.microbit.org
- GamePad library: https://github.com/DFRobot/pxt-gamePad (install via Advanced > Add package)
Wiring Diagram
Plug the two micro:bit into the GamePad for microbit (V2.0) respectively.
Other Preparation Work
Set the micro:bit to the 1th wireless group when booting.
Sample Code
Graphical source program: Dice Game
Result
- Set the wireless to group 1 when booting, and initialize item to 0.
- When the vibration is detected, turn off the LED and initialize the value to 0, and use the acceleration value to produce a random number between 1 and 6.
- Incremental display from 0 to randomly generated number on the LED dot matrix, play the pitch and vibrate motor.
- Send 1~6 random numbers to other main boards via wireless.
- Comparing the random number with the received number. If it is less than the received number, turn off the light, otherwise turn on the light.
Was this article helpful?
