Wiki: A Touch Keyboard Expansion Board for micro:bit - DFRobot

Introduction

This is a Math & Automatic expansion board for micro:bit. Easy to use, and suitable for a wide range of applications. We designed this board for two sorts of application: fun math games and automation control. There are following multiple functions integrated on the board:

We add a acrylic cover at the bottom of the board to make it more durable and delicate, which is also perfect for using in class.

This product supports makecode graphical programming and Mind+ platform.

Specification

Board Overview

RGB Lights/>

Makecode Online Graphical Programming

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

Basic Tutorials

RGB LEDs

RGB LED is composed of three basic colors: red, green and blue. There are 16 RGB LEDs integrated on the top-left corner of every touch-key on the board. Connect the RGB LED to p15 of micro:bit.

  1. Set the brightness of RGB (0~255)

Set Brightness

Result: the brightness of the whole LEDs is 138

  1. Set the LED No. 0 to blue

LED NO.0 Blue

Result: the LED 0 lights up in blue.

  1. Set the LED 4 to 8 to yellow.

LED 4 to 8 light up in yellow

Result: the LED 4 to 8 light up in yellow.

  1. Set LED 3 to purple

LED 4 light up in purple

Result: the LED 3 lights up in purple.

  1. Light up RGB Matrix Pixel

Light up RGB matrix pixel

Matrix Pixel

Result: Light up the LED in form of a matrix in purple. X=1, Y=2. (The original point of the matrix is the upper-left corner.)

  1. RGB LED show Rainbow

RGB LED show rainbow

Result: the LED 0 to 15 show rainbow color.

Read Keyboard Value

To let users programme the touchkeys flexibly, we set two modes to read the keyboard: basic mode and math mode.

  1. Read Keyboard Data (Basic mode)

Basic Mode: in this mode, press a key then you will get the related key value. For instance, press key 2, then you get its value "2". This mode is suitable for password input, game controlling, etc.

Key Value in basic mode:

Key Label Value (numerical)
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
+ 10
- 11
× 12
÷ 13
= 14
DFlogo 15

Show Key Value

  1. Read Key Value (Math mode)

In math mode, the keyboard has the similar function with calculator. For example, when press down key 2, you get a number "2", then press down key 3, you get a number "23". This mode is perfect for math calculation.

We can divide the keyboard into two parts in math mode: numerical key and function key. The former returns numerical value while the latter returns char-type data. Refer to the following chart:

Key Label Value (numerical)
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
Key Label Vlaue (char)
+ +
- -
× ×
÷ ÷
= =
DFlogo DF

Example Code in Math mode: calculator

Calculator

Key Detection Function

  1. Trigger Event: by reading the returned key value, judge if the returned key value is the same as preset key value, if it is, trigger the event, otherwise, not.

Trigger event

Result: show a "heart" pattern on micro:bit LED matrix when key 3 is touched.

  1. Query: by reading the returned key value, query if the touched key value is the same as the preset key value, if it is, do the related actions, otherwise, not.

Query

Result: show a "heart" pattern on micro:bit LED matrix when key 2 is touched.

Motor

Motor speed range: 0~255

Motor

Result: when key 1 is touched, Motor connected with pin M1 rotate at full speed for 1 second.

Vibration Motor

Vibration Motor

Result: when key 3 is touched, vibration motor vibrates for 1 second.

Servo

Servo rotating range: 0~180 degree

Servo

Result: when key 5 is touched, servo S1 rotates 180 degrees and backs to 0 degree 1 second later.

Advanced Tutorials

Automation Control Applications

  1. Colorful Waterfall Light

Result: at first, RGB LEDs of the first row light up in different colors from left to right in turn, when all LEDs turn on, make them go off orderly from the first row. After that, RGB LEDs of the first column light up in various color from top to bottom in turn, and then dies off from bottom to top. LEDs of each column turns on repeatedly in the preset order.

Example Codes:

Colorful Waterfall Light

Waterfall Light Code Download: https://makecode.microbit.org/_EXAWj47md5MU

  1. Touch Music

Result: touch key 1~7, the buzzer makes different sounds; touch the rest to play different music.

Example Codes:

Touch Music

Touch Music Code Download: https://makecode.microbit.org/_aEtYReVjt63P

  1. Countdown Timer

Result: Every RGB LED shows random color in each turn. When all LEDs turns off in one turn, we mark it as 16s. The related time will be displayed on micro:bit LED matrix.

Unit: second

Example Codes:

Countdown Timer

Countdown Timer Example Code Download: https://makecode.microbit.org/_YmzamCJypcYk

  1. Motor Control System

Result: use touchkey 0~9 to conctrol the speed of M2 motor. When key 0 is touched, motor stops; key 9 touched, motor rotates at full speed. Motor speed range from 0 to 255.

Example Codes:

Motor Control System

Motor Control System Example Code Download: https://makecode.microbit.org/_9f5F2zVUFX1T

  1. Remote Wireless Handle

Result: two micro:bit boards will be used in this tutorial. One for touch keypad, one for Maqueen car. Programme the key 2, 4, 6, 8 to control the car to move forward, backward, left, right respectively.

Example Codes:

Remote Wireless Handle

Remote Wireless Handle Example Code Download: https://makecode.microbit.org/_MTwFj1TTvHE3

  1. Anti-thief Lock

Result: touch Key DFlogo to enter 3-digit passward, if the passward is correct, the micro:bit LED matrix show "√" pattern, the buzzer plays the "correct beep sound", and the servo rotates 180 degrees and backs to 0 degree 1s later. Otherwise, micro:bit displays "×" pattern, the buzzer makes the "error beep sound", and the servo keeps still. Press the DFlogo key to enter passward again. Initial passward: 726.

Example Codes:

Anti-thief Lock

Anti-thief Lock Example Code Download: https://makecode.microbit.org/_Lmb5vgT8t5yJ

Math Game Apllications

  1. Lucky Number

Result: shake the expansion board, then one of the 15 RGB LEDs "jump" up and down, and the buzzer makes "jump down sound". At last, the LED will stops at a key. The corresponding key number will be displayed on the micro:bit LED matrix. This is your lucky number. Shake the board again, you can get the another one.

Example Codes:

Lucky Number

Lucky Number Example Codes Download: https://makecode.microbit.org/_W6vemK5fR48k

  1. Comparing Number

Result: press down button A on micro:bit, a countdown will appear on micro:bit LED panel, and it shows a random number; Touch the DFlogo key, the RGB LEDs 0~9 "jump" randomly and then generates a random number. Compare the two numbers. If the former one is bigger, micro:bit LED displays a left arrow; if the latter one is bigger, display a right arrow; if equal, display a "heart" pattern.

Random number range: 0~9

Example Code:

Comparing Number

Comparing Number Example Code Download: https://makecode.microbit.org/_TWCdYPdF7dU2

  1. Number Guessing

Result: touch the DFlogo key, and RGB LEDs flash twice, then the game begins. RGB 0~15 shines randomly for 15 times, meanwhile, micro:bit LED panel displays a countdown and buzzer makes sounds. Players guess which number the RGB LED will stop at, and press down that key before the end of countdown. If you guess right, the buzzer plays "correct beep sound" and LED panel displays the right number. The game goes on. Otherwise, the buzzer plays "game over sound" and LED panel shows the right answer. Game over. You have to touch the DFlogo key to restart. The micro:bit LED matrix will display times of guessing right first when you touch the DFlogo key again, then the game starts again.

Example Codes:

Number Guessing

Number Guessing Example Code Download: https://makecode.microbit.org/_08sMiFbjxA06

  1. Whack a Mole

Result: touch the DFlogo key, and RGB LEDs flash twice, then the game begins. The RGB LEDs on the keyboard will light up randomly in random color. When the LED turns on, players have to touch the corresponding key within preset time, by which to simulate the process of whack a mole. If users hit the right mole, the viration motor vibrates and the buzzer makes sound effect. Once players missed the moles for 10 times continuously, game over. Every time you hit a mole, you get a point. Your final score will be displayed on the micro:bit LED panel. Touch the DFlogo key again to restart the game.

Example Codes:

Whack a Mole

Whack a Mole Example Code Download: https://makecode.microbit.org/_exeFtvTpgCga

  1. Blackjack (Twenty-One)

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

Example Codes:

Blackjack

Blackjack Example Code Download: https://makecode.microbit.org/_Wq2c7fhyD3i2

  1. Math Calculator

Result: use the expansion board as a calculator to do math calculation. Press the key to input the data, and the related RGB will light up, which represents you successfully input the number. The input number will be displayed on the micro:bit LED panel. After the key"=" is pressed, the program will judge which operator you have input first, and then do the math calculation. The result will be circularly displayed on the micro:bit LED matrix for 4 times, waiting for the next calculation.

Example Codes:

Math Calculator

Math Calculator Example Code Download: https://makecode.microbit.org/_4H0VEYTuo0hA

Calculation Competition

Calculation Competition: +, -, ×, ÷.

  1. Addition operation result: generate random A and B within 0~50. Then the micro:bit LED matrix displays A+B for once. Players have to input the correct answer in 10 seconds. If the input answer is right, micro:bit displays "√", if it is not or timeout, display "×".

Example Codes:

Addition Operation

Addition Opeation Example Code Download: https://makecode.microbit.org/_Wos7jJWVrVyK

  1. Subtraction operation result: generate random A and B within 0~50. Then the micro:bit LED matrix displays A-B for once. Players have to input the correct answer in 10 seconds. If the input answer is right, micro:bit displays "√", if it is not or timeout, display "×".

Example Codes:

Subtraction Operation

Subtraction Operation Example Code Download: https://makecode.microbit.org/_MECYEzF147DP

  1. Multiply operation result: generate random A and B within 0~10. Then the micro:bit LED matrix displays A*B for once. Player have to input the correct answer in 10 seconds. If the input answer is right, micro:bit displays "√", if it is not or timeout, display "×".

Example Codes:

Multiply Operation

Multiply Operation Example Code Download: https://makecode.microbit.org/_7sEY7Mh166Wm

  1. Division operation result: generate random A and B within 0~10. Then the micro:bit LED matrix displays A/B for once. Players have to input the correct answer in 10 seconds. If the input answer is right, micro:bit displays "√", if it is not or timeout, display "×".

Example Codes:

Division Operation

Division Operation Example Code Download: https://makecode.microbit.org/_544dyFTy9X2L

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum

More Documents

DFshopping_car1.png Get Math & Automatic for micro:bit from DFRobot Store or DFRobot Distributor.

Turn to the Top