Skip to content

Instantly share code, notes, and snippets.

@sago35
Created October 4, 2021 23:40
Show Gist options
  • Save sago35/aa684d7580e2e7c1434f8b80d6e4c127 to your computer and use it in GitHub Desktop.
Save sago35/aa684d7580e2e7c1434f8b80d6e4c127 to your computer and use it in GitHub Desktop.
TinyGo with QR Code
package main
import (
"image/color"
"time"
"github.com/boombuler/barcode"
"github.com/boombuler/barcode/qr"
"tinygo.org/x/tinyfont"
"tinygo.org/x/tinyfont/freemono"
)
var (
black = color.RGBA{0, 0, 0, 255}
white = color.RGBA{255, 255, 255, 255}
)
func main() {
// display : tinygo.org/x/drivers/ili9341.Device
display.FillScreen(white)
url := `https://tinygo.org/`
qc, _ := qr.Encode(url, qr.M, qr.Auto)
qc, _ = barcode.Scale(qc, 150, 150)
for y := 0; y < qc.Bounds().Max.Y; y++ {
for x := 0; x < qc.Bounds().Max.X; x++ {
r, g, b, a := qc.At(x, y).RGBA()
display.SetPixel(int16(x)+1, int16(y)+1, color.RGBA{R: uint8(r), G: uint8(g), B: uint8(b), A: uint8(a)})
}
}
tinyfont.WriteLine(display, &freemono.Regular9pt7b, 0, int16(qc.Bounds().Max.X)+20, url, black)
for {
time.Sleep(500 * time.Millisecond)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment