Add support for blinking usr leds

This commit is contained in:
Adrian Zankich 2014-09-17 15:20:08 -07:00
parent 1936827ad6
commit 39d3795f5a
2 changed files with 46 additions and 3 deletions

View File

@ -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()
}

View File

@ -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 {