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