tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/pcd8544/setpixel/main.go (about) 1 package main 2 3 import ( 4 "image/color" 5 "machine" 6 "time" 7 8 "tinygo.org/x/drivers/pcd8544" 9 ) 10 11 func main() { 12 dcPin := machine.P3 13 dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput}) 14 rstPin := machine.P4 15 rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput}) 16 scePin := machine.P5 17 scePin.Configure(machine.PinConfig{Mode: machine.PinOutput}) 18 19 machine.SPI0.Configure(machine.SPIConfig{}) 20 21 lcd := pcd8544.New(machine.SPI0, dcPin, rstPin, scePin) 22 lcd.Configure(pcd8544.Config{}) 23 24 var x int16 25 var y int16 26 deltaX := int16(1) 27 deltaY := int16(1) 28 for { 29 pixel := lcd.GetPixel(x, y) 30 c := color.RGBA{255, 255, 255, 255} 31 if pixel { 32 c = color.RGBA{0, 0, 0, 255} 33 } 34 lcd.SetPixel(x, y, c) 35 lcd.Display() 36 37 x += deltaX 38 y += deltaY 39 40 if x == 0 || x == 83 { 41 deltaX = -deltaX 42 } 43 44 if y == 0 || y == 47 { 45 deltaY = -deltaY 46 } 47 time.Sleep(1 * time.Millisecond) 48 } 49 }