Example Code for micro:bit-Dice Fight

This routine uses two micro: bit wireless communication to simulate the game of rolling dice. When running this routine, download the program to two micro: bit motherboards and plug the motherboard into the gamepad.

Hardware Preparation

  • [DFR0536]GamePad for microbit ×2
  • micro:bit motherboards ×2
  • Maqueen Lite ×1

Software Preparation

  • MakeCode programming platform address: https://makecode.microbit.org
  • GamePad library: You can directly program this product on MakeCode without any third-party libraries.

Wiring Diagram

Plug the two micro:bit motherboards into the GamePad for microbit respectively.

Other Preparation Work

Download the program to two micro: bit motherboards and plug the motherboard into the gamepad.

Sample Code

Program for Maqueen Lite: https://makecode.microbit.org/_7odPvqFRXHey

Microbit Gamepad Expansion Board

Result

  1. When starting up, set the wireless to group 1 and initialize the value of the variable item to 0;
  2. When vibration is detected, turn off the LED and initialize value to 0; The value of acceleration is used to generate a random number between 1 and 6;
  3. It is displayed incrementally from 1 to the number randomly generated on the LED dot matrix; And play the tone;
  4. Send random numbers from 1 to 6 to another motherboard wirelessly;
  5. Compare the received number with the random number generated by yourself. If the number is greater than the other party, the vibration motor will vibrate, otherwise it will not vibrate;

Note: If compilation or download fails, please update the McQueen library version in makecode.

Was this article helpful?

ON THIS PAGE

TOP