Add support for blinking usr leds
This commit is contained in:
parent
1936827ad6
commit
39d3795f5a
|
@ -0,0 +1,32 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/beaglebone"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
|
||||
led := gpio.NewLedDriver(beagleboneAdaptor, "led", "usr0")
|
||||
|
||||
work := func() {
|
||||
gobot.Every(1*time.Second, func() {
|
||||
led.Toggle()
|
||||
})
|
||||
}
|
||||
|
||||
robot := gobot.NewRobot("blinkBot",
|
||||
[]gobot.Connection{beagleboneAdaptor},
|
||||
[]gobot.Device{led},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bufio"
|
||||
"fmt"
|
||||
"github.com/hybridgroup/gobot"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
@ -13,7 +14,8 @@ import (
|
|||
const (
|
||||
Slots = "/sys/devices/bone_capemgr.*"
|
||||
Ocp = "/sys/devices/ocp.*"
|
||||
I2CLocation = "/dev/i2c-1"
|
||||
I2CLocation = "/dev/i2c-1"
|
||||
UsrLed = "/sys/devices/ocp.3/gpio-leds.8/leds/beaglebone:green:"
|
||||
)
|
||||
|
||||
var pins = map[string]int{
|
||||
|
@ -171,8 +173,17 @@ func (b *BeagleboneAdaptor) DigitalRead(pin string) int {
|
|||
}
|
||||
|
||||
func (b *BeagleboneAdaptor) DigitalWrite(pin string, val byte) {
|
||||
i := b.digitalPin(pin, "w")
|
||||
b.digitalPins[i].digitalWrite(strconv.Itoa(int(val)))
|
||||
if strings.Contains(pin, "usr") {
|
||||
fi, err := os.OpenFile(UsrLed+pin+"/brightness", os.O_WRONLY|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer fi.Close()
|
||||
fi.WriteString(strconv.Itoa(int(val)))
|
||||
} else {
|
||||
i := b.digitalPin(pin, "w")
|
||||
b.digitalPins[i].digitalWrite(strconv.Itoa(int(val)))
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BeagleboneAdaptor) AnalogRead(pin string) int {
|
||||
|
|
Loading…
Reference in New Issue