forked from hybridgroup/gopherbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathled.go
44 lines (36 loc) · 709 Bytes
/
led.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
package gopherbot
import (
"machine"
"time"
)
// LEDDevice controls any of the standard LEDs on Gopherbot.
type LEDDevice struct {
machine.Pin
Speed time.Duration
}
// StatusLED returns the built-in LED of the Circuit Playground Express.
func StatusLED() *LEDDevice {
led := machine.LED
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
return &LEDDevice{
Pin: led,
Speed: 500 * time.Millisecond,
}
}
// On turns on the LED.
func (a *LEDDevice) On() {
a.High()
}
// Off turns off the LED.
func (a *LEDDevice) Off() {
a.Low()
}
// Blink starts the LED blinking repeatedly.
func (a *LEDDevice) Blink() {
for {
a.On()
time.Sleep(a.Speed)
a.Off()
time.Sleep(a.Speed)
}
}