Files
drivers/examples/tmp102/main.go
T
Ayke van Laethem 16d2b71820 all: do not use machine.TWI_FREQ_* constants
These constants were always a bit weird:

  * they use an uncommon name (TWI instead of I2C)
  * they don't follow Go naming conventions (CamelCase)
  * the constants don't provide much value: their name is their value
    (100KHZ => 100e3).

Therefore, I propose we remove them and replace them with regular
numeric constants.
2021-02-06 11:21:37 +01:00

29 lines
388 B
Go

package main
import (
"fmt"
"machine"
"time"
"tinygo.org/x/drivers/tmp102"
)
func main() {
machine.I2C0.Configure(machine.I2CConfig{
Frequency: 400e3,
})
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)
}
}