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
sumd = 0
prevval = None
def trend(newval):
global prevval, sumd
if prevval is not None:
olddiff = diffs.pop(0)
newdiff = newval - prevval
diffs.append(newdiff)
sumd = sumd - olddiff + newdiff
print(prevval, newval, newdiff, sumd)
prevval = newval
if abs(sumd) >= SIGNIFICANT:
return sumd
return 0 # no change
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)
while True:
reading = pin0.read_analog()
display.clear()
t = trend(reading)
if t < 0:
display.show(DISCHARGING)
elif t > 0:
display.show(CHARGING)
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)
Page 19