Example Code for micro:bit-Rock-Paper-Scissors
This routine uses two micro:bit wireless communication to simulate the game of rock-paper-scissors. Press the corresponding button to display the corresponding pattern on the LED dot matrix and send the corresponding number, and compare the received number with your own number to determine the winning or losing.
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 two micro:bit to the 1th wireless group to ensure normal communication.
Sample Code
Graphical source program: Rock-Paper-Scissors
Result
- First, you should set the two main boards are in the 1th wireless group, so that they can communicate with each other.
- When the left button is pressed, LED dot matrix displays the scissors, and sends the number 1.
- When the down button is pressed, LED dot matrix displays the rock, and sends the number 2.
- When the right button is pressed, LED dot matrix displays the paper, and sends the number 3.
- In the infinite loop, compare the wireless received numbers with your own Numbers;if you lost,it will display “×", if you win, it will show "√".
- After showing the result, clear all data.
Was this article helpful?
