mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-26 10:38:41 +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
36 lines
662 B
Go
36 lines
662 B
Go
package main
|
|
|
|
import (
|
|
"machine"
|
|
"time"
|
|
|
|
"tinygo.org/x/drivers/lps22hb"
|
|
)
|
|
|
|
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 := lps22hb.New(machine.I2C1)
|
|
sensor.Configure()
|
|
|
|
if !sensor.Connected() {
|
|
println("LPS22HB not connected!")
|
|
return
|
|
}
|
|
|
|
for {
|
|
p, _ := sensor.ReadPressure()
|
|
t, _ := sensor.ReadTemperature()
|
|
println("p =", float32(p)/1000.0, "hPa / t =", float32(t)/1000.0, "*C")
|
|
time.Sleep(time.Second)
|
|
// note: the device would power down itself after each query
|
|
}
|
|
|
|
}
|