mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-26 10:38:41 +00:00
0b6bfda8cf
This is in preparation of PR https://github.com/tinygo-org/tinygo/pull/1693, which makes machine.I2C0 and similar objects of pointer type, so they can be freely passed around.
28 lines
360 B
Go
28 lines
360 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"machine"
|
|
"time"
|
|
|
|
"tinygo.org/x/drivers/adt7410"
|
|
)
|
|
|
|
var (
|
|
i2c = machine.I2C0
|
|
sensor = adt7410.New(i2c)
|
|
)
|
|
|
|
func main() {
|
|
|
|
i2c.Configure(machine.I2CConfig{Frequency: machine.TWI_FREQ_400KHZ})
|
|
sensor.Configure()
|
|
|
|
for {
|
|
temp := sensor.ReadTempF()
|
|
fmt.Printf("temperature: %f\r\n", temp)
|
|
time.Sleep(time.Second)
|
|
}
|
|
|
|
}
|