Skip to content

Instantly share code, notes, and snippets.

@nobonobo
Created September 11, 2021 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobonobo/ae58d815b652f47d459c5f79e9a425e3 to your computer and use it in GitHub Desktop.
Save nobonobo/ae58d815b652f47d459c5f79e9a425e3 to your computer and use it in GitHub Desktop.
TinyGo + PineTime64 サンプルを https://play.tinygo.org/ で試す
package main
import (
"image/color"
"time"
"machine"
"tinygo.org/x/drivers/st7789"
)
var (
black = color.RGBA{0, 0, 0, 255}
white = color.RGBA{255, 255, 255, 255}
red = color.RGBA{255, 0, 0, 255}
blue = color.RGBA{0, 0, 255, 255}
green = color.RGBA{0, 255, 0, 255}
)
func main() {
machine.SPI0.Configure(machine.SPIConfig{
SDI: machine.SPI0_SDI_PIN,
SDO: machine.SPI0_SDO_PIN,
SCK: machine.SPI0_SCK_PIN,
Frequency: 8000000,
Mode: 3,
})
const (
resetPin = machine.LCD_RESET
dcPin = machine.LCD_RS
csPin = machine.LCD_CS
blPin = machine.LCD_BACKLIGHT_MID
)
display := st7789.New(machine.SPI0, resetPin, dcPin, csPin , blPin)
display.Configure(st7789.Config{
Width: 240,
Height: 320,
})
width, height := display.Size()
println(width, height)
display.FillScreen(black)
o := int16(height - width)
height = height - o
display.FillRectangle(0, 0+o, width/2, height/2, white)
display.FillRectangle(width/2, 0+o, width/2, height/2, red)
display.FillRectangle(0, height/2+o, width/2, height/2, green)
display.FillRectangle(width/2, height/2+o, width/2, height/2, blue)
display.FillRectangle(width/4, height/4+o, width/2, height/2, black)
for {
time.Sleep(time.Hour)
}
}
@nobonobo
Copy link
Author

https://play.tinygo.org/ をひらいて
PineTime(dev kit)を選択してこのコードを貼り付けるとWeb上で描画の確認ができるよ!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment