forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firmata_aip1640.go
55 lines (44 loc) · 1.01 KB
/
firmata_aip1640.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
// +build example
//
// Do not build by default.
/*
How to run
Pass serial port to use as the first param:
go run examples/firmata_aip1640.go /dev/ttyACM0
*/
package main
import (
"os"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/firmata"
)
func main() {
firmataAdaptor := firmata.NewAdaptor(os.Args[1])
// In the WEMOS D1 Mini LED Matrix Shield clockPin = 14, dataPin = 13
aip1640 := gpio.NewAIP1640Driver(firmataAdaptor, "14", "13")
smiles := [3][8]byte{
{0x3C, 0x42, 0xA5, 0x81, 0xA5, 0x99, 0x42, 0x3C}, // happy :)
{0x3C, 0x42, 0xA5, 0x81, 0xBD, 0x81, 0x42, 0x3C}, // normal :|
{0x3C, 0x42, 0xA5, 0x81, 0x99, 0xA5, 0x42, 0x3C}, // sad :(
}
s := 0
work := func() {
aip1640.Clear()
gobot.Every(600*time.Millisecond, func() {
aip1640.DrawMatrix(smiles[s])
aip1640.Display()
s++
if s > 2 {
s = 0
}
})
}
robot := gobot.NewRobot("aip1640Bot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{aip1640},
work,
)
robot.Start()
}