tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/adafruit4650/main.go (about)

     1  package main
     2  
     3  import (
     4  	"image/color"
     5  	"machine"
     6  	"tinygo.org/x/drivers"
     7  	"tinygo.org/x/drivers/adafruit4650"
     8  	"tinygo.org/x/tinyfont"
     9  	"tinygo.org/x/tinyfont/freemono"
    10  )
    11  
    12  func main() {
    13  	machine.I2C0.Configure(machine.I2CConfig{})
    14  
    15  	dev := adafruit4650.New(machine.I2C0)
    16  
    17  	err := dev.Configure()
    18  	if err != nil {
    19  		panic(err)
    20  	}
    21  
    22  	drawPlus(&dev)
    23  	drawHelloWorld(&dev)
    24  
    25  	err = dev.Display()
    26  	if err != nil {
    27  		panic(err)
    28  	}
    29  }
    30  
    31  func drawPlus(d drivers.Displayer) {
    32  	for i := int16(0); i < 128; i++ {
    33  		d.SetPixel(i, 32, color.RGBA{R: 1})
    34  	}
    35  	for i := int16(0); i < 64; i++ {
    36  		d.SetPixel(64, i, color.RGBA{R: 1})
    37  	}
    38  }
    39  
    40  func drawHelloWorld(d drivers.Displayer) {
    41  	tinyfont.WriteLine(d, &freemono.Regular9pt7b, 0, 32, "Hello World!", color.RGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff})
    42  }