Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions 25_cputemp/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package main

import (
"fmt"
"image/color"
"machine"
"time"

"tinygo.org/x/drivers"
"tinygo.org/x/drivers/ssd1306"
"tinygo.org/x/tinyfont"
"tinygo.org/x/tinyfont/shnm"
)

var (
white = color.RGBA{R: 0xFF, G: 0xFF, B: 0xFF, A: 0xFF}
black = color.RGBA{R: 0x00, G: 0x00, B: 0x00, A: 0xFF}
)

type celsius float32

func (c celsius) String() string {
return fmt.Sprintf("温度:%4.1f℃", c)
}

func main() {

machine.I2C0.Configure(machine.I2CConfig{
Frequency: 2.8 * machine.MHz,
SDA: machine.GPIO12,
SCL: machine.GPIO13,
})

display := ssd1306.NewI2C(machine.I2C0)
display.Configure(ssd1306.Config{
Address: 0x3C,
Width: 128,
Height: 64,
})
display.SetRotation(drivers.Rotation180)
display.ClearDisplay()
time.Sleep(50 * time.Millisecond)

for {
temp := celsius(float32(machine.ReadTemperature()) / 1000)
println(temp.String())

display.ClearBuffer()
tinyfont.WriteLine(display, &shnm.Shnmk12, 5, 10, temp.String(), white)
display.Display()
time.Sleep(time.Second)
}
}
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ smoketest:
tinygo build -o ./out/22_buzzer.uf2 --target waveshare-rp2040-zero --size short ./22_buzzer
tinygo build -o ./out/23_akatonbo.uf2 --target waveshare-rp2040-zero --size short ./23_akatonbo
tinygo build -o ./out/24_sht40.uf2 --target waveshare-rp2040-zero --size short ./24_sht40
tinygo build -o ./out/25_cputemp.uf2 --target waveshare-rp2040-zero --size short ./25_cputemp
tinygo build -o ./out/80_checker.uf2 --target waveshare-rp2040-zero --size short ./80_checker
Loading