tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/waveshare-epd/epd2in9/main.go (about) 1 package main 2 3 import ( 4 "machine" 5 6 "image/color" 7 8 "time" 9 10 "tinygo.org/x/drivers/waveshare-epd/epd2in9" 11 ) 12 13 var display epd2in9.Device 14 15 const ( 16 width = 128 17 height = 296 18 ) 19 20 func main() { 21 machine.SPI0.Configure(machine.SPIConfig{ 22 Frequency: 8000000, 23 Mode: 0, 24 }) 25 26 display = epd2in9.New(machine.SPI0, machine.GPIO2, machine.GPIO3, machine.GPIO4, machine.GPIO5) 27 display.Configure(epd2in9.Config{ 28 Width: width, 29 LogicalWidth: width, 30 Height: height, 31 }) 32 33 black := color.RGBA{1, 1, 1, 255} 34 white := color.RGBA{0, 0, 0, 255} 35 36 display.ClearBuffer() 37 println("Clear the display") 38 display.ClearDisplay() 39 display.WaitUntilIdle() 40 println("Waiting for 2 seconds") 41 time.Sleep(2 * time.Second) 42 43 // Show a checkered board 44 for i := int16(0); i < width/8; i++ { 45 for j := int16(0); j < height/8; j++ { 46 if (i+j)%2 == 0 { 47 showRect(i*8, j*8, 8, 8, black) 48 } 49 } 50 } 51 println("Show checkered board") 52 display.Display() 53 display.WaitUntilIdle() 54 println("Waiting for 2 seconds") 55 time.Sleep(2 * time.Second) 56 57 println("Set partial lut") 58 display.SetLUT(false) // partial updates (faster, but with some ghosting) 59 println("Show smaller striped area") 60 for i := int16(40); i < 88; i++ { 61 for j := int16(83); j < 166; j++ { 62 if (i+j)%4 == 0 || (i+j)%4 == 1 { 63 display.SetPixel(i, j, black) 64 } else { 65 display.SetPixel(i, j, white) 66 } 67 } 68 } 69 70 display.Display() 71 display.WaitUntilIdle() 72 73 display.DeepSleep() 74 75 println("You could remove power now") 76 } 77 78 func showRect(x int16, y int16, w int16, h int16, c color.RGBA) { 79 for i := x; i < x+w; i++ { 80 for j := y; j < y+h; j++ { 81 display.SetPixel(i, j, c) 82 } 83 } 84 }