Skip to content

Commit 3b5fce2

Browse files
committed
Add filtering to wind direction analogue reading
1 parent 9e6a2a0 commit 3b5fce2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

weatherbit.ts

+7
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,19 @@ namespace weatherbit {
263263
* Read the wind direction from the wind vane.
264264
* Returns the compass bearing of the wind direction in degrees
265265
*/
266+
let windDirLast = 9999
266267
//% weight=20 blockId="weatherbit_windDir" block="wind direction"
267268
export function windDirection(): number {
268269
startWindMonitoring();
269270

271+
/* read until reading stable */
270272
let windDir = 0
271273
windDir = pins.analogReadPin(AnalogPin.P1)
274+
while (Math.abs(windDir-windDirLast)>10) { /* 10 is an arbitary number based on guess and observation */
275+
windDirLast = windDir
276+
windDir = pins.analogReadPin(AnalogPin.P1)
277+
}
278+
272279

273280
if (windDir < 911 && windDir > 894)
274281
return 0

0 commit comments

Comments
 (0)