nicebadge/tutorial/basics/step4/main.go

41 lines
970 B
Go
Raw Normal View History

2026-04-18 11:01:06 +00:00
package main
import (
"image/color"
"machine"
"tinygo.org/x/drivers/st7789"
"tinygo.org/x/tinyfont"
"tinygo.org/x/tinyfont/freesans"
)
func main() {
machine.SPI0.Configure(machine.SPIConfig{
SCK: machine.P1_01,
SDO: machine.P1_02,
Frequency: 8000000,
Mode: 0,
})
display := st7789.New(machine.SPI0,
machine.P1_15, // TFT_RESET
machine.P1_13, // TFT_DC
machine.P0_10, // TFT_CS
machine.P0_09) // TFT_LITE
display.Configure(st7789.Config{
Rotation: st7789.ROTATION_90,
Width: 135,
Height: 240,
RowOffset: 40,
ColumnOffset: 53,
})
// clear the screen to black
display.FillScreen(color.RGBA{0, 0, 0, 255})
// the display is 240x135 pixels in landscape orientation
tinyfont.WriteLine(&display, &freesans.Bold12pt7b, 10, 50, "Hello", color.RGBA{R: 255, G: 255, B: 0, A: 255})
tinyfont.WriteLine(&display, &freesans.Bold12pt7b, 10, 90, "Gophers!", color.RGBA{R: 255, G: 0, B: 255, A: 255})
}