-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
65 lines (57 loc) · 1.26 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
package main
import (
"fmt"
"net"
"os"
"time"
magichome "github.com/apoclyps/magic-home/pkg"
"github.com/apoclyps/magic-home/pkg/lights"
)
// Cycle an array of color presets for a device by setting color to each color with a delay between changes.
func main() {
// Create a new Magic Home LED Strip Controller
d, err := magichome.NewDevice(net.ParseIP("192.168.0.50"), "", "", "")
if err != nil {
fmt.Printf("Error configuring device: %s\n", err)
os.Exit(1)
}
// Turn LED Strip Device On
_, err = d.Power(true)
if err != nil {
fmt.Printf("Error powering device: %s\n", err)
os.Exit(1)
}
var colors []lights.Color = []lights.Color{
lights.White(),
lights.Black(),
lights.Red(),
lights.Blue(),
lights.Green(),
lights.Yellow(),
lights.Pink(),
lights.Cyan(),
lights.Silver(),
lights.Gray(),
lights.Maroon(),
lights.Olive(),
lights.Purple(),
lights.Teal(),
lights.Navy(),
lights.Orange(),
}
// Cycle device colors
for _, l := range colors {
err := d.SetDeviceColor(l)
if err != nil {
fmt.Println("Error setting device color: ", err)
os.Exit(1)
}
time.Sleep(3 * time.Second)
}
// Turn LED Strip Device On
_, err = d.Power(false)
if err != nil {
fmt.Printf("Error powering device: %s\n", err)
os.Exit(1)
}
}