mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-14 11:53:41 +00:00
Add driver for TMP102 low-power digital temperature sensor (#141)
* tmp102: add driver and example
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user