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

     1  // This example uses the settings for the thermistor that is built in to the
     2  // Adafruit Circuit Playground Express.
     3  package main
     4  
     5  import (
     6  	"machine"
     7  	"time"
     8  
     9  	"tinygo.org/x/drivers/thermistor"
    10  )
    11  
    12  const ADC_PIN = machine.TEMPSENSOR
    13  
    14  func main() {
    15  	machine.InitADC()
    16  
    17  	sensor := thermistor.New(ADC_PIN)
    18  	sensor.Configure()
    19  
    20  	for {
    21  		temp, _ := sensor.ReadTemperature()
    22  		println("Temperature:", temp/1000, "°C")
    23  
    24  		time.Sleep(2 * time.Second)
    25  	}
    26  }