Files
Yannis Huber 6f213e97c3 Add driver for TMP102 low-power digital temperature sensor (#141)
* tmp102: add driver and example
2020-04-03 13:11:46 +02:00

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)
}
}