mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-03 06:27:47 +00:00
bee7422c3a
Fix HTS221, LPS22HB and APDS9960 drivers and their examples for Arduino Nano 33 BLE: * Update hts221_nano_33_ble.go * Update lps22hb_nano_33_ble.go * Update apds9960_nano_33_ble.go
41 lines
676 B
Go
41 lines
676 B
Go
package main
|
|
|
|
import (
|
|
"machine"
|
|
"time"
|
|
|
|
"tinygo.org/x/drivers/apds9960"
|
|
)
|
|
|
|
func main() {
|
|
|
|
// 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,
|
|
})
|
|
|
|
sensor := apds9960.New(machine.I2C1)
|
|
|
|
// use default settings
|
|
sensor.Configure(apds9960.Configuration{})
|
|
|
|
if !sensor.Connected() {
|
|
println("APDS-9960 not connected!")
|
|
return
|
|
}
|
|
|
|
sensor.EnableProximity() // enable proximity engine
|
|
|
|
for {
|
|
|
|
if sensor.ProximityAvailable() {
|
|
p := sensor.ReadProximity()
|
|
println("Proximity:", p)
|
|
}
|
|
time.Sleep(time.Millisecond * 100)
|
|
}
|
|
|
|
}
|