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

     1  package main
     2  
     3  import (
     4  	"machine"
     5  
     6  	"time"
     7  
     8  	"tinygo.org/x/drivers/vl53l1x"
     9  )
    10  
    11  func main() {
    12  	machine.I2C0.Configure(machine.I2CConfig{
    13  		Frequency: 400000,
    14  	})
    15  	sensor := vl53l1x.New(machine.I2C0)
    16  	connected := sensor.Connected()
    17  	if !connected {
    18  		println("VL53L1X device not found")
    19  		return
    20  	}
    21  	println("VL53L1X device found")
    22  	sensor.Configure(true)
    23  	sensor.SetMeasurementTimingBudget(50000)
    24  	sensor.StartContinuous(50)
    25  	for {
    26  		sensor.Read(true)
    27  		println("Distance (mm):", sensor.Distance())
    28  		println("Status:", sensor.Status())
    29  		println("Peak signal rate (cps):", sensor.SignalRate())
    30  		println("Ambient rate (cps):", sensor.AmbientRate())
    31  		println("---")
    32  		time.Sleep(100 * time.Millisecond)
    33  	}
    34  }