-
Notifications
You must be signed in to change notification settings - Fork 0
/
square.go
78 lines (64 loc) · 1.48 KB
/
square.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
package main
import (
"time"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/api"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
)
func main() {
gbot := gobot.NewGobot()
a := api.NewAPI(gbot)
a.Start()
board := edison.NewEdisonAdaptor("edison")
red := gpio.NewLedDriver(board, "red", "3")
green := gpio.NewLedDriver(board, "green", "5")
blue := gpio.NewLedDriver(board, "blue", "6")
button := gpio.NewButtonDriver(board, "button", "7")
enabled := true
work := func() {
red.Brightness(0xff)
green.Brightness(0x00)
blue.Brightness(0x00)
flash := false
on := true
gobot.Every(250*time.Millisecond, func() {
if enabled {
if flash {
if on {
red.Brightness(0x00)
green.Brightness(0xff)
blue.Brightness(0x00)
on = false
} else {
red.Brightness(0xff)
green.Brightness(0x00)
blue.Brightness(0x00)
on = true
}
}
}
})
button.On(gpio.ButtonPush, func(data interface{}) {
flash = true
})
button.On(gpio.ButtonRelease, func(data interface{}) {
flash = false
red.Brightness(0x00)
green.Brightness(0x00)
blue.Brightness(0xff)
})
}
robot := gobot.NewRobot(
"square of fire",
[]gobot.Connection{board},
[]gobot.Device{red, green, blue, button},
work,
)
robot.AddCommand("enable", func(params map[string]interface{}) interface{} {
enabled = !enabled
return enabled
})
gbot.AddRobot(robot)
gbot.Start()
}