If buttons A and B are not enough for your project, you can connect extra buttons to the micro:bit quite simply.
This page shows a simple setup and program to read button presses. Most buttons are based on two pins and can be connected up as you see in the circuit on this page. The same principle can be extended to a lot of toggle, rocker and DIP switches as well as the switches built into some rotary encoders.
One pin of the button should be connected to 3V. The other pin should be connected, via a 10K Ohm resistor, to GND. You read the signal from the button from the button pin that is connected to GND. This will give a 1 when the button is pressed and a 0 when it is not.
This is a simple program just to allow you to see that the button presses are being registered.
from microbit import * while True: buttonState = pin0.read_digital() if buttonState==1: display.show(Image.YES) else: display.clear() sleep(20)
- Think about what you want your extra buttons to do. You can use extra buttons as modifiers, like shift or CTRL keys on the keyboard. You could write your program so that a button A press is treated differently if one of your other buttons is pressed at the same time.
- You can connect enough buttons to give you a simple piano-like keyboard that you could use to play different notes on a buzzer or headphone hack.
- You may want to have a go at the Simon Game project in this section of the site.