tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/waveshare-epd/epd2in13/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/epd2in13" 11 ) 12 13 var display epd2in13.Device 14 15 func main() { 16 machine.SPI0.Configure(machine.SPIConfig{ 17 Frequency: 8000000, 18 Mode: 0, 19 }) 20 21 display = epd2in13.New(machine.SPI0, machine.P6, machine.P7, machine.P8, machine.P9) 22 display.Configure(epd2in13.Config{}) 23 24 black := color.RGBA{1, 1, 1, 255} 25 white := color.RGBA{0, 0, 0, 255} 26 27 display.ClearBuffer() 28 println("Clear the display") 29 display.ClearDisplay() 30 display.WaitUntilIdle() 31 println("Waiting for 2 seconds") 32 time.Sleep(2 * time.Second) 33 34 // Show a checkered board 35 for i := int16(0); i < 16; i++ { 36 for j := int16(0); j < 25; j++ { 37 if (i+j)%2 == 0 { 38 showRect(i*8, j*10, 8, 10, black) 39 } 40 } 41 } 42 println("Show checkered board") 43 display.Display() 44 display.WaitUntilIdle() 45 println("Waiting for 2 seconds") 46 time.Sleep(2 * time.Second) 47 48 println("Set partial lut") 49 display.SetLUT(false) // partial updates (faster, but with some ghosting) 50 println("Show smaller striped area") 51 for i := int16(40); i < 88; i++ { 52 for j := int16(83); j < 166; j++ { 53 if (i+j)%4 == 0 || (i+j)%4 == 1 { 54 display.SetPixel(i, j, black) 55 } else { 56 display.SetPixel(i, j, white) 57 } 58 } 59 } 60 61 // There are two memory areas in the display, once the display is refreshed, memory areas are auto-toggled. 62 // DisplayRect needs to be called twice 63 display.DisplayRect(40, 83, 48, 83) 64 display.WaitUntilIdle() 65 display.DisplayRect(40, 83, 48, 83) 66 display.WaitUntilIdle() 67 68 println("You could remove power now") 69 } 70 71 func showRect(x int16, y int16, w int16, h int16, c color.RGBA) { 72 for i := x; i < x+w; i++ { 73 for j := y; j < y+h; j++ { 74 display.SetPixel(i, j, c) 75 } 76 } 77 }