tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/ssd1306/spi_128x64/main.go (about) 1 package main 2 3 import ( 4 "image/color" 5 "machine" 6 "time" 7 8 "tinygo.org/x/drivers/ssd1306" 9 ) 10 11 func main() { 12 machine.SPI0.Configure(machine.SPIConfig{ 13 Frequency: 8000000, 14 }) 15 display := ssd1306.NewSPI(machine.SPI0, machine.P8, machine.P7, machine.P9) 16 display.Configure(ssd1306.Config{ 17 Width: 128, 18 Height: 64, 19 }) 20 21 display.ClearDisplay() 22 23 x := int16(64) 24 y := int16(32) 25 deltaX := int16(1) 26 deltaY := int16(1) 27 for { 28 pixel := display.GetPixel(x, y) 29 c := color.RGBA{255, 255, 255, 255} 30 if pixel { 31 c = color.RGBA{0, 0, 0, 255} 32 } 33 display.SetPixel(x, y, c) 34 display.Display() 35 36 x += deltaX 37 y += deltaY 38 39 if x == 0 || x == 127 { 40 deltaX = -deltaX 41 } 42 43 if y == 0 || y == 63 { 44 deltaY = -deltaY 45 } 46 time.Sleep(1 * time.Millisecond) 47 } 48 }