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

     1  package main
     2  
     3  import (
     4  	"machine"
     5  
     6  	"image/color"
     7  
     8  	"tinygo.org/x/drivers/ssd1331"
     9  )
    10  
    11  func main() {
    12  	machine.SPI0.Configure(machine.SPIConfig{
    13  		Frequency: 8000000,
    14  	})
    15  	display := ssd1331.New(machine.SPI0, machine.P6, machine.P7, machine.P8)
    16  	display.Configure(ssd1331.Config{})
    17  	display.SetContrast(0x30, 0x20, 0x30)
    18  	width, height := display.Size()
    19  
    20  	white := color.RGBA{255, 255, 255, 255}
    21  	red := color.RGBA{255, 0, 0, 255}
    22  	blue := color.RGBA{0, 0, 255, 255}
    23  	green := color.RGBA{0, 255, 0, 255}
    24  	black := color.RGBA{0, 0, 0, 255}
    25  
    26  	display.FillScreen(black)
    27  
    28  	display.FillRectangle(0, 0, width/2, height/2, white)
    29  	display.FillRectangle(width/2, 0, width/2, height/2, red)
    30  	display.FillRectangle(0, height/2, width/2, height/2, green)
    31  	display.FillRectangle(width/2, height/2, width/2, height/2, blue)
    32  	display.FillRectangle(width/4, height/4, width/2, height/2, black)
    33  }