tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/vl6180x/main.go (about) 1 package main 2 3 import ( 4 "machine" 5 6 "tinygo.org/x/drivers/vl6180x" 7 8 "time" 9 ) 10 11 func main() { 12 time.Sleep(3 * time.Second) 13 machine.I2C0.Configure(machine.I2CConfig{ 14 Frequency: 400000, 15 }) 16 sensor := vl6180x.New(machine.I2C0) 17 connected := sensor.Connected() 18 if !connected { 19 println("VL6180X device not found") 20 return 21 } 22 println("VL6180X device found") 23 sensor.Configure(true) 24 var value uint16 25 var status uint8 26 for { 27 value = sensor.Read() 28 status = sensor.ReadStatus() 29 println("Distance (mm):", value) 30 println("Status:", status) 31 println("---") 32 time.Sleep(100 * time.Millisecond) 33 } 34 }