Instructions

How It Works
The P0_MAX constant sets the maximum value expected from pin P0, and this is
the value that represents 100% charged. You might have to experiment with the
value here to get the best performance from your barchart.
barchart() draws a horizontal line on the display, by turning on a different
number of LEDs. 'y' is the position on the display where the barchart will appear, 'v'
is the value to display, and 'vmax' is the maximum value to expect. The value is
capped (with min()) and scaled (with the divide) to turn on between 0 and 5 LEDs.
The main program loops round forever reading the Charge% pin, displaying a
barchart, and checking the buttons. Button A = fan off, Button B = fan on.
Screen Designs for a Charge Direction Display
Let's build a new display feature that shows whether your Solar Store is being
charged or discharged. This will make it easier for you to decide whether to use the
fan or conserve energy for later.
CHARGING DISCHARGING
Code for a Charge Direction Display (MicroPython)
This program is called 04_indicator.py.
from microbit import *
P0_MAX = 812
SIGNIFICANT = 3
CHARGING = Image("90000:09000:90000:00000:00000")
DISCHARGING = Image("00090:00009:00090:00000:00000")
diffs = [0 for i in range(10)]
Page 18