2014-03-23 01:55:32 +01:00
|
|
|
// +build ignore
|
|
|
|
|
2014-03-23 11:17:58 +01:00
|
|
|
// LED example, works OOTB on a BBB.
|
|
|
|
|
2014-03-23 01:55:32 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-04-04 22:13:16 +02:00
|
|
|
"flag"
|
2014-03-23 01:55:32 +01:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/kidoman/embd"
|
2014-04-06 03:20:09 +02:00
|
|
|
|
2014-04-11 05:40:17 +02:00
|
|
|
_ "github.com/kidoman/embd/host/bbb"
|
2014-03-23 01:55:32 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-04-04 22:13:16 +02:00
|
|
|
flag.Parse()
|
|
|
|
|
2014-03-23 01:55:32 +01:00
|
|
|
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 {
|
2014-04-24 22:57:44 +02:00
|
|
|
case <-time.After(250 * time.Millisecond):
|
2014-03-23 01:55:32 +01:00
|
|
|
if err := led.Toggle(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2014-04-24 22:57:44 +02:00
|
|
|
fmt.Println("Toggled")
|
2014-03-23 01:55:32 +01:00
|
|
|
case <-quit:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|