Instructions

Code for a Simple Bar-Chart (MicroPython)
MicroPython doesn't have a barchart feature built in, so you have to provide the
code for it yourself.
This program is called 04_meter.py.
from microbit import *
P0_MAX = 812
def barchart(y, v, vmax):
v = min(v, vmax)
leds = int(v * 5 / vmax)
for x in range(leds):
display.set_pixel(x, y, 9)
# main program
while True:
reading = pin0.read_analog()
display.clear()
barchart(4, reading, P0_MAX)
if button_a.was_pressed():
pin2.write_digital(0) # off
if button_b.was_pressed():
pin2.write_digital(1) # on
sleep(1000) # 1 second
Barchart Screens
The barchart moves from the left to the right by showing more dots for a larger
value, like this:
Page 17