tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/hcsr04/main.go (about)

     1  package main
     2  
     3  import (
     4  	"machine"
     5  	"time"
     6  
     7  	"tinygo.org/x/drivers/hcsr04"
     8  )
     9  
    10  func main() {
    11  	sensor := hcsr04.New(machine.D10, machine.D9)
    12  	sensor.Configure()
    13  
    14  	println("Ultrasonic starts")
    15  	for {
    16  		println("Distance:", sensor.ReadDistance(), "mm")
    17  
    18  		time.Sleep(100 * time.Millisecond)
    19  	}
    20  }