forked from tinygo-org/gobadge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
109 lines (92 loc) · 1.96 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"image/color"
"machine"
"time"
"tinygo.org/x/drivers/lis3dh"
"tinygo.org/x/drivers/ws2812"
"tinygo.org/x/drivers/shifter"
"tinygo.org/x/drivers/st7735"
)
var display st7735.Device
var buttons shifter.Device
var leds ws2812.Device
var bzrPin machine.Pin
var accel lis3dh.Device
const (
BLACK = iota
WHITE
RED
SNAKE
TEXT
)
var colors = []color.RGBA{
color.RGBA{0, 0, 0, 255},
color.RGBA{255, 255, 255, 255},
color.RGBA{250, 0, 0, 255},
color.RGBA{0, 200, 0, 255},
color.RGBA{160, 160, 160, 255},
}
var snakeGame = NewSnakeGame()
func main() {
machine.SPI1.Configure(machine.SPIConfig{
SCK: machine.SPI1_SCK_PIN,
SDO: machine.SPI1_SDO_PIN,
SDI: machine.SPI1_SDI_PIN,
Frequency: 8000000,
})
machine.I2C0.Configure(machine.I2CConfig{SCL: machine.SCL_PIN, SDA: machine.SDA_PIN})
accel = lis3dh.New(machine.I2C0)
accel.Address = lis3dh.Address0
accel.Configure()
display = st7735.New(machine.SPI1, machine.TFT_RST, machine.TFT_DC, machine.TFT_CS, machine.TFT_LITE)
display.Configure(st7735.Config{
Rotation: st7735.ROTATION_90,
})
buttons = shifter.NewButtons()
buttons.Configure()
neo := machine.NEOPIXELS
neo.Configure(machine.PinConfig{Mode: machine.PinOutput})
leds = ws2812.New(neo)
bzrPin = machine.A0
bzrPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
speaker := machine.SPEAKER_ENABLE
speaker.Configure(machine.PinConfig{Mode: machine.PinOutput})
speaker.High()
for {
switch menu() {
case 0:
Badge()
break
case 1:
snakeGame.Loop()
break
case 2:
Leds()
break
case 3:
Accel3D()
break
case 4:
GameOfLife()
break
case 5:
Music()
break
default:
break
}
println("LOOP")
time.Sleep(1 * time.Second)
}
}
func getRainbowRGB(i uint8) color.RGBA {
if i < 85 {
return color.RGBA{i * 3, 255 - i*3, 0, 255}
} else if i < 170 {
i -= 85
return color.RGBA{255 - i*3, 0, i * 3, 255}
}
i -= 170
return color.RGBA{0, i * 3, 255 - i*3, 255}
}