mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-04 15:07:46 +00:00
16d2b71820
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.
29 lines
388 B
Go
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)
|
|
}
|
|
|
|
}
|