-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8f3fcc
commit 1b8aad1
Showing
7 changed files
with
216 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,74 @@ | ||
package main | ||
|
||
import ( | ||
"machine" | ||
|
||
"image/color" | ||
|
||
"machine" | ||
"time" | ||
|
||
"tinygo.org/x/drivers/waveshare-epd/epd2in9" | ||
"tinygo.org/x/drivers" | ||
"tinygo.org/x/drivers/waveshare-epd/epd2in66b" | ||
"tinygo.org/x/tinyfont" | ||
"tinygo.org/x/tinyfont/freemono" | ||
) | ||
|
||
var display epd2in9.Device | ||
|
||
const ( | ||
width = 128 | ||
height = 296 | ||
var ( | ||
black = color.RGBA{0, 0, 0, 0xff} | ||
white = color.RGBA{0xff, 0xff, 0xff, 0xff} | ||
red = color.RGBA{0xff, 0, 0, 0xff} | ||
) | ||
|
||
func main() { | ||
machine.SPI0.Configure(machine.SPIConfig{ | ||
Frequency: 8000000, | ||
Mode: 0, | ||
}) | ||
machine.Serial.Configure(machine.UARTConfig{}) | ||
time.Sleep(2 * time.Second) | ||
|
||
display = epd2in9.New(machine.SPI0, machine.GPIO2, machine.GPIO3, machine.GPIO4, machine.GPIO5) | ||
display.Configure(epd2in9.Config{ | ||
Width: width, | ||
LogicalWidth: width, | ||
Height: height, | ||
machine.SPI1.Configure(machine.SPIConfig{ | ||
Frequency: epd2in66b.Baudrate, | ||
}) | ||
|
||
black := color.RGBA{1, 1, 1, 255} | ||
white := color.RGBA{0, 0, 0, 255} | ||
println("started") | ||
|
||
display.ClearBuffer() | ||
println("Clear the display") | ||
display.ClearDisplay() | ||
display.WaitUntilIdle() | ||
println("Waiting for 2 seconds") | ||
time.Sleep(2 * time.Second) | ||
|
||
// Show a checkered board | ||
for i := int16(0); i < width/8; i++ { | ||
for j := int16(0); j < height/8; j++ { | ||
if (i+j)%2 == 0 { | ||
showRect(i*8, j*8, 8, 8, black) | ||
} | ||
} | ||
display := epd2in66b.New(machine.SPI1) | ||
err := display.Configure(epd2in66b.Config{}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
println("Show checkered board") | ||
display.Display() | ||
display.WaitUntilIdle() | ||
println("Waiting for 2 seconds") | ||
time.Sleep(2 * time.Second) | ||
|
||
println("Set partial lut") | ||
display.SetLUT(false) // partial updates (faster, but with some ghosting) | ||
println("Show smaller striped area") | ||
for i := int16(40); i < 88; i++ { | ||
for j := int16(83); j < 166; j++ { | ||
if (i+j)%4 == 0 || (i+j)%4 == 1 { | ||
display.SetPixel(i, j, black) | ||
} else { | ||
display.SetPixel(i, j, white) | ||
} | ||
} | ||
err = display.Reset() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
display.Display() | ||
display.WaitUntilIdle() | ||
println("draw checkerboard") | ||
drawCheckerBoard(&display) | ||
|
||
println("draw 'hello'") | ||
tinyfont.WriteLineRotated(&display, &freemono.Bold24pt7b, 40, 10, "Hello!", white, tinyfont.ROTATION_90) | ||
tinyfont.WriteLineRotated(&display, &freemono.Bold12pt7b, 10, 10, "tinygo rocks", white, tinyfont.ROTATION_90) | ||
err = display.Display() | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
display.DeepSleep() | ||
func drawCheckerBoard(display drivers.Displayer) { | ||
s := 8 | ||
width, height := display.Size() | ||
for x := 0; x <= int(width)-s; x += s { | ||
for y := 0; y <= int(height)-s; y += s { | ||
c := red | ||
if (x/s)%2 == (y/s)%2 { | ||
c = black | ||
} | ||
|
||
println("You could remove power now") | ||
showRect(display, x, y, s, s, c) | ||
} | ||
} | ||
} | ||
|
||
func showRect(x int16, y int16, w int16, h int16, c color.RGBA) { | ||
func showRect(display drivers.Displayer, x int, y int, w int, h int, c color.RGBA) { | ||
for i := x; i < x+w; i++ { | ||
for j := y; j < y+h; j++ { | ||
display.SetPixel(i, j, c) | ||
display.SetPixel(int16(i), int16(j), c) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.