micro:bit Rock Paper Scissors: Shake to Play
Shake the board: the display counts 3, 2, 1 and then shows rock, paper or scissors at random. The accelerometer feels the shake (was_gesture) and random.choice picks the hand. No extra parts are needed.

Video
Circuit Diagram

Source Code
1# ─────────────────────────────────────────
2# BlueGrays · bluegrays.com
3# micro:bit Rock Paper Scissors: Shake to Play
4# ─────────────────────────────────────────
5# Shake the board: the display counts 3, 2, 1 and then shows rock, paper
6# or scissors at random. Shake at the same time as a friend and see who
7# wins. No extra parts are needed.
8#
9# Pins:
10# LED -> Onboard 5x5 LED display
11# ACCEL -> Onboard accelerometer
12
13from microbit import *
14import random
15
16# ============ SETTINGS ============
17COUNT_MS = 400 # Time each number stays on (ms)
18LOOP_MS = 50 # Loop pause (ms)
19
20# Rock is a small filled square, paper a big empty square and scissors a built-in image.
21ROCK = Image("00000:09990:09990:09990:00000")
22PAPER = Image("99999:90009:90009:90009:99999")
23HANDS = [ROCK, PAPER, Image.SCISSORS]
24
25display.show(Image.TARGET)
26
27while True:
28 if accelerometer.was_gesture("shake"):
29 for number in [3, 2, 1]:
30 display.show(number)
31 sleep(COUNT_MS)
32 display.show(random.choice(HANDS)) # Result
33 sleep(LOOP_MS)
34FAQ
How do I play with one board?
You make rock, paper or scissors with your hand while the board shows its own choice on the display. Open your hand when the count reaches 1 and see who won. With two boards, two players shake at the same time and compare displays.
Which shape means what?
The small filled square in the middle is rock. The big empty square with lit edges is paper. Scissors is one of the board's built-in images and looks like real scissors. Rock beats scissors, scissors beat paper and paper beats rock.
How do I put this code on the micro:bit?
The code is MicroPython. Open the micro:bit Python Editor (python.microbit.org) on a computer, delete the code that is there and paste this one. Connect the board with a USB cable and press Send to micro:bit. If that button does not work, use Save to download the .hex file and copy it to the drive called MICROBIT. You can rebuild the same project with blocks in MakeCode, but this code cannot be pasted there.
Does it work on the older micro:bit (V1) too?
The code is written for the micro:bit V2. Projects that only use the LED display, buttons A and B and the accelerometer also run on a V1. The speaker, the microphone and the touch logo exist only on the V2, so code that uses them gives an error on a V1. If your board has a speaker on the back and a gold logo on the front, it is a V2.
