mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-09 09:23:39 +00:00
remove last traces of legacy I2C calls
This commit is contained in:
@@ -8,33 +8,42 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// Sleep to catch any errors through the serial monitor.
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
bus := machine.I2C0
|
||||
// use Nano 33 BLE Sense's internal I2C bus
|
||||
machine.I2C1.Configure(machine.I2CConfig{
|
||||
SCL: machine.SCL1_PIN,
|
||||
SDA: machine.SDA1_PIN,
|
||||
Frequency: machine.TWI_FREQ_400KHZ,
|
||||
err := bus.Configure(machine.I2CConfig{
|
||||
SCL: machine.GP1,
|
||||
SDA: machine.GP0,
|
||||
Frequency: 400 * machine.KHz,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
sensor := apds9960.New(machine.I2C1)
|
||||
sensor := apds9960.New(bus)
|
||||
|
||||
// use default settings
|
||||
sensor.Configure(apds9960.Configuration{})
|
||||
|
||||
if !sensor.Connected() {
|
||||
println("APDS-9960 not connected!")
|
||||
println("err:", sensor.Err())
|
||||
return
|
||||
}
|
||||
|
||||
sensor.EnableProximity() // enable proximity engine
|
||||
|
||||
println("APDS connected!")
|
||||
err = sensor.EnableProximity() // enable proximity engine
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
for {
|
||||
|
||||
if sensor.ProximityAvailable() {
|
||||
p := sensor.ReadProximity()
|
||||
println("Proximity:", p)
|
||||
}
|
||||
if err := sensor.Err(); err != nil {
|
||||
println(err.Error())
|
||||
}
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user