Have you ever played "Guess the Number"? This is a very easy-to-build mini game machine that plays "Guess the Number" with you. We designed this DIY project to encourage physical play and help kids learn programming. It uses a MU Vision sensor to sense the number cards, through which the player will try to guess the random number that the machine has chosen.
The setup is all explained in this picture.
A MU vision sensor that can recognize printed number cards is connected to the Micro:bit via I2C bus. The two PCB boards and a speaker are held together using a stand built from LEGO technic pieces so that the camera is looking down at a 45 degree angle. Make sure there is nothing to block the camera view to the front of the Micro:bit where the player will present the number card to the machine.
You will need to connect 6 wires. The speaker has two wires connecting to the "0" and "GND" pin of Micro:bit. The MU Vision sensor has 4 wires connecting to the I2C bus -- 3V, pin 19 (SCL), pin 20 (SDA)and GND.
In the picture, we just solder the wires to the Micro:bit contact pad. You can also use one of the breakout board for micro:bit to connect the wires.
The MU Vision sensor is the main AI module that recognizes different number cards. It has I2C output port that can be used to connect to the Micro:bit (pin 19 and pin 20).
1. To connect to Micro:bit, the vision sensor's left DIP switch 2 need to set to "ON" to use the I2C mode.
2. The vision sensor is mounted upside down (the sensor connector facing toward player) so that when the player present the number card to the machine it is "frontal" from the player's point-of-view.
1. Import the MUVisionSensorIII library
By selecting "Advanced" -> "Extensions", and type "mu-opensource/MuVisionSensorIII-MakeCode" in the search box. Select the "Muvs" extension from the result
You will now find the MuVisionSensor blocks like this:
2. Initialization of MU Vision Sensor in the on start block and set it to use I2C bus.
and Add Number Card algorithm
After running "on start", the vision sensor's LEDs should start blinking in red color. If it detects any number card, the LEDs will change to blue color.
3. In the Forever loop, add code to process the detection result from MU Vision Sensor.
4. Display the result on the LED matrix
We use a custom function to display the number recognition result.
Note: Since we placed the Micro:bit vertically, the number on the LED display need to be rotated by 90 degree.
5. Game Logic
You can program micro:bit to give out a little hint for the secret number.
You can also life to the game for a bit more fun. We use the left column of the LED matrix to display the "life bar"
6. Add music
That's it. Due to the space reason, not all code are shown in the figure above. You can find the full scratch code here.
This tutorial teaches you how to build a mini game machine using Micro:bit and the MU Vision Sensor. With the help of visual recognition from the MU Vision Sensor, you can build many similar "physical play" games on the Micro:bit platform.