Sensor
#struct SensorAn HC-SR04: the pin that triggers it and the pin the echo comes back on.
| Name | Type | Description |
|---|---|---|
trigger | int = 0 | The pin wired to the trigger input. |
echo | int = 0 | The pin wired to the echo output. |
import hw.board
import hw.hcsr04
func main:
sonar := hcsr04.Open(4, 5)
println hcsr04.MAX_ECHO_US
board.SimSetPulse(5, 583 as u64)
println hcsr04.EchoMicros(sonar)
println hcsr04.DistanceMm(sonar), hcsr04.DistanceCm(sonar)
board.SimSetPulse(5, 0 as u64)
println hcsr04.DistanceMm(sonar)
end38000 583 99 9.9 -1