Instructions
Table Of Contents
- Introduction
- Parts
- Using Alligator Clips
- Solar Board Reference
- Project 1 – Sun Finder
- Project 2 – Garden Light
- Project 3 – Self Charging Cooling Fan
- The BBC micro:bit
- Getting Code to Run on the micro:bit
- Project 4 – Adding an Energy Meter
- Project 5 – Energy Logger
- Connecting Up
- Code for the Energy Logger (MakeCode)
- How it works
- Connecting to Your PC
- Pairing Your micro:bit With MakeCode
- Showing the Device Console Graph
- Capturing Data From a Charge and Discharge Cycle
- Downloading Data
- Getting Data into a Spreadsheet Program
- Analysing the Data
- Graphing the Data
- Results
- Understanding the Data
- Understanding Duty Cycle
- How the Solar Store Works
- Project 6 – Intelligent Cooling Fan
- Troubleshooting
- About the Author
- Learning
- Monk Makes Kits
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