mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-26 10:38:41 +00:00
6f213e97c3
* tmp102: add driver and example
29 lines
406 B
Go
29 lines
406 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"machine"
|
|
"time"
|
|
|
|
"tinygo.org/x/drivers/tmp102"
|
|
)
|
|
|
|
func main() {
|
|
machine.I2C0.Configure(machine.I2CConfig{
|
|
Frequency: machine.TWI_FREQ_400KHZ,
|
|
})
|
|
|
|
thermo := tmp102.New(machine.I2C0)
|
|
thermo.Configure(tmp102.Config{})
|
|
|
|
for {
|
|
|
|
temp, _ := thermo.ReadTemperature()
|
|
|
|
print(fmt.Sprintf("%.2f°C\r\n", float32(temp)/1000.0))
|
|
|
|
time.Sleep(time.Millisecond * 1000)
|
|
}
|
|
|
|
}
|