Example Code for micro:bit-Blackjack (Twenty-One)

Last revision 2025/12/31

The article offers a comprehensive guide to setting up and playing Blackjack on micro:bit, including hardware and software preparation, wiring instructions, library installation, and example code for a two-player mode.

Hardware Preparation

  • Math & Automatic expansion board for micro:bit, Quantity: 1
  • micro:bit, Quantity: 2

Software Preparation

Makecode graphical programming, Mind+ platform.
Makecode Library Address.
About how to install a software library?

Wiring Diagram

Two micro:bit boards for two players.

Other Preparation Work

Install the Makecode library from https://github.com/DFRobot/pxt-Math-Automatic.
About how to install a software library?

Sample Code

Blackjack
Blackjack Example Code Download

Result

Two players battle mode. The micro:bit LED matrix displays "0", which is the intial points of both players. Touch the DFlogo key to deal card, at the same time, the total card points will constantly showed on the micro:bit, the player can press the DFlogo key to ask for more cards if he thinks his points are not high enough. Touch the "=" key to stop dealing cards, and wait for another player to finish. Compare the players' point. The one who get the most point will be the winner and his micro:bit LED panel will display "WIN", the another one gets "LOSE". The micro:bit boards display "=" when both of them get same point. Please note that if the player's point is over 21, he will lose the game. The micro:bit will display "0" when one turn is over. Point for each card: 0~9.

Was this article helpful?

TOP