Skip to content

Commit c15b1a8

Browse files
committed
Add sunlight power function (stolen ADC from soildMoisture)
1 parent a181ebc commit c15b1a8

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

pxt.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
],
2323
"public": true,
2424
"targetVersions": {
25-
"target": "4.0.11",
25+
"target": "4.0.16",
2626
"targetId": "microbit"
2727
},
2828
"supportedTargets": [

tests.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@ loops.everyInterval(1000, () => {
5050
//basic.showArrow(weatherbit.directionArrowName(dir))
5151
//serial.writeValue("rain", weatherbit.rain())
5252
//serial.writeValue("rainRate", weatherbit.rainRate())
53-
serial.writeValue("wind", weatherbit.windSpeed())
54-
})
53+
serial.writeValue("Sunlight", weatherbit.sunlight())
54+
basic.showNumber(weatherbit.sunlight())
55+
})

weatherbit.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,23 @@ namespace weatherbit {
581581

582582

583583
// Functions for interfacing with the soil moisture and soil temperature (aquaponics)
584-
584+
// but we have stolen the soil moisture ADC to read the power from a solar cell into a resistive load.
585+
586+
/**
587+
* Reads the Sunlight level from the same ADC as the soil moisture
588+
* Returns a value between 0 and 1023. 0 being dark and 1023 being blazing sunshine.
589+
* Assuming a solar cell 50mmx38mm driving into a 32 ohm load
590+
* Power = L^2 * 3^2 / (1024^2 * 0.05 * 0.038 * 32) = L^2 / 7084 W/m^2
591+
*/
592+
//% weight=11 blockGap=8 blockId="weatherbit_sunlight" block="sunlight"
593+
export function sunlight(): number {
594+
let light = pins.analogReadPin(AnalogPin.P0)
595+
return light * light / 7084 // units of W/m^2
596+
}
585597

586598
/**
587599
* Reads the Moisture Level from the Soil Moisture Sensor.
588-
* Returns a value between 0 and 1023. 0 being dry and 1023 being wet.
600+
* Returns a value between 0 and 1023. 0 being dry and 1023 being wet.
589601
*/
590602
//% weight=11 blockGap=8 blockId="weatherbit_soilMoisture" block="soil moisture"
591603
export function soilMoisture(): number {

0 commit comments

Comments
 (0)