Skip to content
Merged
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
38 changes: 38 additions & 0 deletions 17_oled_japanese_font/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

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

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

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,
//Rotation: drivers.Rotation180,
})
display.SetRotation(drivers.Rotation180)
display.ClearDisplay()
time.Sleep(50 * time.Millisecond)

white := color.RGBA{R: 0xFF, G: 0xFF, B: 0xFF, A: 0xFF}

tinyfont.WriteLine(&display, &shnm.Shnmk12, 5, 10, "こんにちは世界", white)
tinyfont.WriteLine(&display, &gophers.Regular32pt, 5, 50, "ABCEF", white)
display.Display()
}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,16 @@ $ tinygo flash --target waveshare-rp2040-zero --size short ./10_oled_rotated/
$ tinygo flash --target waveshare-rp2040-zero --size short ./11_oled_animation/
```

### 日本語を表示する

現在 BDF と OTF/TTF フォントのいずれかが表示できます。
zero-kb02 のような 1bit color の小型ディスプレイだと BDF フォントが適しています。
以下にて使用することができます。

```shell
$ tinygo flash --target waveshare-rp2040-zero --size short ./17_oled_japanese_font/
```

## キー押下状態を取得する

zero-kb02 は matrix と呼ばれる配線方法を使ってキーが接続されています。
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ require (
github.com/tinygo-org/pio v0.0.0-20240626192653-0b4cbef45f9b // indirect
tinygo.org/x/drivers v0.28.1-0.20240825183126-07216d3051aa // indirect
tinygo.org/x/tinydraw v0.4.0 // indirect
tinygo.org/x/tinyfont v0.4.0 // indirect
tinygo.org/x/tinyfont v0.4.1-0.20241022105211-0b3702cd6364 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ tinygo.org/x/tinydraw v0.4.0 h1:U9V0mHz8/jPShKjlh199vCfq1ARFyUOD1b+FfqIwV8c=
tinygo.org/x/tinydraw v0.4.0/go.mod h1:WCV/EMljTv8w04iAxjv+fRD6/4ffx0afATYeJlN90Yo=
tinygo.org/x/tinyfont v0.4.0 h1:XexPKEKiHInf6p4CMCJwsIheVPY0T46HUs6ictYyZfE=
tinygo.org/x/tinyfont v0.4.0/go.mod h1:7nVj3j3geqBoPDzpFukAhF1C8AP9YocMsZy0HSAcGCA=
tinygo.org/x/tinyfont v0.4.1-0.20241019115309-be919cfc7fd0 h1:aIwyRBwsSv6wDenbIcUZ2cqOGz7vDIK2Bz2X3W53qms=
tinygo.org/x/tinyfont v0.4.1-0.20241019115309-be919cfc7fd0/go.mod h1:7nVj3j3geqBoPDzpFukAhF1C8AP9YocMsZy0HSAcGCA=
tinygo.org/x/tinyfont v0.4.1-0.20241022105211-0b3702cd6364 h1:dYjlzfKPssWsVKfGUp1rPmsvErVc/cE5WB2OviNbsJ0=
tinygo.org/x/tinyfont v0.4.1-0.20241022105211-0b3702cd6364/go.mod h1:7nVj3j3geqBoPDzpFukAhF1C8AP9YocMsZy0HSAcGCA=