(gpio.Pin MY_PIN).do:
.do:
pulse-counter
do
wait-for
pin.get
yield
do
spawn
task
yield
wait-for
import gpio
import pulse-counter
main:
pin/gpio.Pin := gpio.Pin in-pin --input --pull-up
pulse-count/pulse-counter.Unit := pulse-counter.Unit pin
task::get-task
get-task:
while true:
pulse-count.clear
start := Time.now.ms-since-epoch
sleep --ms=3000
pulse-total := pulse-count.value
now := Time.now.ms-since-epoch
print "pulse-total: " + pulse-total.stringify // <-- 30.000
last-speed = ((pulse-total.to-float / 2.0) * 60000.0 / (now - start).to-float).round
print "last-speed: " + last-speed.stringify // <-- 300.000
glitch-filter-ns
Unit
print "pulse-total: $pulse-total"
to-float