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