-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
57 lines (49 loc) · 1.2 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
package main
import (
"fmt"
"net"
"time"
magichome "github.com/apoclyps/magic-home/pkg"
"github.com/apoclyps/magic-home/pkg/lights"
)
// Cycle an array of color temperatures for a device by setting color to each color with a delay between changes.
func main() {
// Create a new Magic Home LED Strip Controller
controller, err := magichome.NewController(net.ParseIP("192.168.0.50"), 5577)
if err != nil {
fmt.Println("Magic Home Controller Error: ", err)
return
}
// Turn LED Strip Controller On
err = controller.SetState(magichome.On)
if err != nil {
fmt.Println("Set State Error: ", err)
return
}
var temperatures = []lights.Color{
lights.Candle(),
lights.Tungsen40W(),
lights.Tungsen100W(),
lights.Halogen(),
lights.CarbonArc(),
lights.HighNoonSun(),
lights.DirectSunlight(),
lights.OvercastSky(),
lights.ClearBlueSky(),
}
// Cycle device tempatures
for _, l := range temperatures {
err := controller.SetColor(l)
if err != nil {
fmt.Println("Error: ", err)
return
}
time.Sleep(3 * time.Second)
}
// And finaly close the connection to LED Strip Controller
err = controller.Close()
if err != nil {
fmt.Println("Magic Home Controller Error: ", err)
return
}
}