mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-08 17:03:39 +00:00
Initial support for VL6180x sensor
required changes
This commit is contained in:
committed by
Ron Evans
parent
2a2e897261
commit
6f05615f3e
@@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"tinygo.org/x/drivers/vl6180x"
|
||||
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
time.Sleep(3 * time.Second)
|
||||
machine.I2C0.Configure(machine.I2CConfig{
|
||||
Frequency: 400000,
|
||||
})
|
||||
sensor := vl6180x.New(machine.I2C0)
|
||||
connected := sensor.Connected()
|
||||
if !connected {
|
||||
println("VL6180X device not found")
|
||||
return
|
||||
}
|
||||
println("VL6180X device found")
|
||||
sensor.Configure(true)
|
||||
var value uint16
|
||||
var status uint8
|
||||
for {
|
||||
value = sensor.Read()
|
||||
status = sensor.ReadStatus()
|
||||
println("Distance (mm):", value)
|
||||
println("Status:", status)
|
||||
println("---")
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user