tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/tmp102/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"machine"
     6  	"time"
     7  
     8  	"tinygo.org/x/drivers/tmp102"
     9  )
    10  
    11  func main() {
    12  	machine.I2C0.Configure(machine.I2CConfig{
    13  		Frequency: machine.TWI_FREQ_400KHZ,
    14  	})
    15  
    16  	thermo := tmp102.New(machine.I2C0)
    17  	thermo.Configure(tmp102.Config{})
    18  
    19  	for {
    20  
    21  		temp, _ := thermo.ReadTemperature()
    22  
    23  		print(fmt.Sprintf("%.2f°C\r\n", float32(temp)/1000.0))
    24  
    25  		time.Sleep(time.Millisecond * 1000)
    26  	}
    27  
    28  }