-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsequence_test.go
68 lines (55 loc) · 1.29 KB
/
sequence_test.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
package blink_test
import (
"time"
"github.com/fgrosse/blink"
)
func ExampleSequence() {
led, err := blink.New()
if err != nil {
panic(err)
}
defer led.Close()
d := 500 * time.Millisecond
s := blink.NewSequence().
Fade(blink.Red, d).
Fade(blink.Green, d).
Fade(blink.Blue, d).
Wait(1 * time.Second).
Off()
// blocks until s is done
err = s.Play(led)
if err != nil {
panic(err)
}
}
func ExampleSequence_Loop() {
led, err := blink.New()
if err != nil {
panic(err)
}
defer led.FadeOutClose()
firstLoop := blink.NewSequence().
Fade(blink.Red, 250*time.Millisecond).
Fade(blink.Blue, 250*time.Millisecond).
LoopN(2) // loops 2 times
secondLoop := firstLoop.
Fade(blink.Green, 250*time.Millisecond).
LoopN(4) // loops 4 times
myBlue := blink.MustParseColor("#6666ff")
entireLoop, c := secondLoop.
Start(). // instruct the next loop to start at this position
Set(myBlue, 200*time.Millisecond).
Set(myBlue.Multiply(0.8), 200*time.Millisecond).
Set(myBlue.Multiply(0.6), 200*time.Millisecond).
Set(myBlue.Multiply(0.4), 200*time.Millisecond).
Loop() // restarts the sequence until c is closed
go func() {
// stop the whole loop after ten seconds
time.Sleep(10 * time.Second)
close(c)
}()
err = entireLoop.Play(led)
if err != nil {
panic(err)
}
}