-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathedison_grove_lcd.go
74 lines (63 loc) · 1.48 KB
/
edison_grove_lcd.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
//go:build example
// +build example
//
// Do not build by default.
package main
import (
"fmt"
"time"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/i2c"
"gobot.io/x/gobot/v2/platforms/intel-iot/edison"
)
func main() {
board := edison.NewAdaptor()
screen := i2c.NewGroveLcdDriver(board)
work := func() {
if err := screen.Write("hello"); err != nil {
fmt.Println(err)
}
if err := screen.SetRGB(255, 0, 0); err != nil {
fmt.Println(err)
}
gobot.After(5*time.Second, func() {
if err := screen.Clear(); err != nil {
fmt.Println(err)
}
if err := screen.Home(); err != nil {
fmt.Println(err)
}
if err := screen.SetRGB(0, 255, 0); err != nil {
fmt.Println(err)
}
// set a custom character in the first position
if err := screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"]); err != nil {
fmt.Println(err)
}
// add the custom character at the end of the string
if err := screen.Write("goodbye\nhave a nice day " + string(byte(0))); err != nil {
fmt.Println(err)
}
gobot.Every(500*time.Millisecond, func() {
if err := screen.Scroll(false); err != nil {
fmt.Println(err)
}
})
})
if err := screen.Home(); err != nil {
fmt.Println(err)
}
time.Sleep(1 * time.Second)
if err := screen.SetRGB(0, 0, 255); err != nil {
fmt.Println(err)
}
}
robot := gobot.NewRobot("screenBot",
[]gobot.Connection{board},
[]gobot.Device{screen},
work,
)
if err := robot.Start(); err != nil {
panic(err)
}
}