5-Position Switch
5-position switch
This is like a thumbstick or joystick, but without levels. While a thumbstick can tell how far you have pushed in some direction, the 5-position switch only knows if it has been pushed up, down, left, right, or not at all.

Parts
(1) 5-Position Switch 27801
(4) Jumper wires
(5) Resistors – 220 Ω (red-red-brown-gold)
Schematic

Wiring

Script
The 5-position switch has built-in “external” pull-up resistors. So all built-in pull-up/down resistors in the micro:bit I/O pins used in the script are disabled with …NO_PULL settings.
# 5-position-switch
from microbit import *
pin16.set_pull(pin16.NO_PULL)
pin14.set_pull(pin15.NO_PULL)
pin15.set_pull(pin14.NO_PULL)
pin16.set_pull(pin13.NO_PULL)
pin8.set_pull(pin8.NO_PULL)
while True:
u = pin16.read_digital()
r = pin15.read_digital()
d = pin14.read_digital()
l = pin13.read_digital()
c = pin8.read_digital()
print(u, r, d, l, c)
if u == 0:
display.show('U')
elif r == 0:
display.show('R')
elif d == 0:
display.show('D')
elif l == 0:
display.show('L')
elif c == 0:
display.show('C')
else:
display.show(Image.SQUARE_SMALL)
sleep(100)
Tests
Without any pushing on the button lever, the 5-position switch will be in its detent position and micro:bit module’s 5×5 LED matrix display will display a small square. If you press up, right, down, left, or center (into toward the breadboard), the micro:bit will display the first letter of the direction:
- U: up
- R: right
- D: down
- L: left
- C: center, into toward the breadboard