mirror of
https://github.com/kidoman/embd
synced 2025-07-03 03:47:33 +02:00
led: support led functionality on the bbb
This commit is contained in:
parent
f7b316332e
commit
bf8a4be4d9
9 changed files with 322 additions and 3 deletions
2
samples/.gitignore
vendored
2
samples/.gitignore
vendored
|
@ -8,6 +8,8 @@ gpiodetect
|
|||
gpiodirect
|
||||
gpioshort
|
||||
l3gd20
|
||||
led
|
||||
ledshort
|
||||
lsm303
|
||||
mcp4725
|
||||
pca9685
|
||||
|
|
44
samples/led.go
Normal file
44
samples/led.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
|
||||
"github.com/kidoman/embd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := embd.InitLED(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer embd.CloseLED()
|
||||
|
||||
led, err := embd.NewLED(3)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer func() {
|
||||
led.Off()
|
||||
led.Close()
|
||||
}()
|
||||
|
||||
quit := make(chan os.Signal, 1)
|
||||
signal.Notify(quit, os.Interrupt, os.Kill)
|
||||
defer signal.Stop(quit)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-time.After(500 * time.Millisecond):
|
||||
if err := led.Toggle(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("Toggled\n")
|
||||
case <-quit:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
18
samples/ledshort.go
Normal file
18
samples/ledshort.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/kidoman/embd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
embd.InitLED()
|
||||
defer embd.CloseLED()
|
||||
|
||||
embd.LEDOn(3)
|
||||
time.Sleep(1 * time.Second)
|
||||
embd.LEDOff(3)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue