tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/ssd1306/spi_thumby/main.go (about) 1 // This example using the SSD1306 OLED display over SPI on the Thumby board 2 // A very tiny 72x40 display. 3 package main 4 5 import ( 6 "image/color" 7 "machine" 8 "time" 9 10 "tinygo.org/x/drivers/ssd1306" 11 ) 12 13 func main() { 14 machine.SPI0.Configure(machine.SPIConfig{}) 15 display := ssd1306.NewSPI(machine.SPI0, machine.THUMBY_DC_PIN, machine.THUMBY_RESET_PIN, machine.THUMBY_CS_PIN) 16 display.Configure(ssd1306.Config{ 17 Width: 72, 18 Height: 40, 19 ResetCol: ssd1306.ResetValue{28, 99}, 20 ResetPage: ssd1306.ResetValue{0, 5}, 21 }) 22 23 display.ClearDisplay() 24 25 x := int16(36) 26 y := int16(20) 27 deltaX := int16(1) 28 deltaY := int16(1) 29 for { 30 pixel := display.GetPixel(x, y) 31 c := color.RGBA{255, 255, 255, 255} 32 if pixel { 33 c = color.RGBA{0, 0, 0, 255} 34 } 35 display.SetPixel(x, y, c) 36 display.Display() 37 38 x += deltaX 39 y += deltaY 40 41 if x == 0 || x == 71 { 42 deltaX = -deltaX 43 } 44 45 if y == 0 || y == 39 { 46 deltaY = -deltaY 47 } 48 time.Sleep(1 * time.Millisecond) 49 } 50 }