mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 19:43:44 +00:00
70b3ece6ec
Replace ADCChannel.ReadTemperature() with a simple ReadTemperature function. Not all chips will have a temperature sensor that is read by sampling an ADC channel. The replacement ReadTemperature is simpler and more generic to other chip families. This breaks chips that were relying on the previous ReadTemperature method. I hope it won't break a lot of existing code. If it does, a fallback can be added.
24 lines
355 B
Go
24 lines
355 B
Go
// Read the internal temperature sensor of the chip.
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"machine"
|
|
"time"
|
|
)
|
|
|
|
type celsius float32
|
|
|
|
func (c celsius) String() string {
|
|
return fmt.Sprintf("%4.1f℃", c)
|
|
}
|
|
|
|
func main() {
|
|
for {
|
|
temp := celsius(float32(machine.ReadTemperature()) / 1000)
|
|
println("temperature:", temp.String())
|
|
time.Sleep(time.Second)
|
|
}
|
|
}
|