up2: useful constant values to access the built-in LEDs
Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
parent
38b019ff36
commit
7c50801753
|
@ -14,10 +14,10 @@ import (
|
|||
|
||||
func main() {
|
||||
b := up2.NewAdaptor()
|
||||
red := gpio.NewLedDriver(b, "red")
|
||||
blue := gpio.NewLedDriver(b, "blue")
|
||||
green := gpio.NewLedDriver(b, "green")
|
||||
yellow := gpio.NewLedDriver(b, "yellow")
|
||||
red := gpio.NewLedDriver(b, up2.LEDRed)
|
||||
blue := gpio.NewLedDriver(b, up2.LEDBlue)
|
||||
green := gpio.NewLedDriver(b, up2.LEDGreen)
|
||||
yellow := gpio.NewLedDriver(b, up2.LEDYellow)
|
||||
|
||||
work := func() {
|
||||
red.Off()
|
||||
|
|
|
@ -80,6 +80,13 @@ r := up2.NewAdaptor()
|
|||
led := gpio.NewLedDriver(r, "13")
|
||||
```
|
||||
|
||||
You can also use the values `up2.LEDRed`, `up2.LEDBlue`, `up2.LEDGreen`, and `up2.LEDYellow` as pin reference to access the 4 built-in LEDs. For example:
|
||||
|
||||
```go
|
||||
r := up2.NewAdaptor()
|
||||
led := gpio.NewLedDriver(r, up2.LEDRed)
|
||||
```
|
||||
|
||||
## How to Connect
|
||||
|
||||
### Compiling
|
||||
|
|
|
@ -14,6 +14,20 @@ import (
|
|||
"gobot.io/x/gobot/sysfs"
|
||||
)
|
||||
|
||||
const (
|
||||
// LEDRed is the built-in red LED.
|
||||
LEDRed = "red"
|
||||
|
||||
// LEDBlue is the built-in blue LED.
|
||||
LEDBlue = "blue"
|
||||
|
||||
// LEDGreen is the built-in green LED.
|
||||
LEDGreen = "green"
|
||||
|
||||
// LEDYellow is the built-in yellow LED.
|
||||
LEDYellow = "yellow"
|
||||
)
|
||||
|
||||
type sysfsPin struct {
|
||||
pin int
|
||||
pwmPin int
|
||||
|
@ -110,7 +124,7 @@ func (c *Adaptor) DigitalRead(pin string) (val int, err error) {
|
|||
// DigitalWrite writes digital value to the specified pin.
|
||||
func (c *Adaptor) DigitalWrite(pin string, val byte) (err error) {
|
||||
// is it one of the built-in LEDs?
|
||||
if pin == "red" || pin == "blue" || pin == "green" || pin == "yellow" {
|
||||
if pin == LEDRed || pin == LEDBlue || pin == LEDGreen || pin == LEDYellow {
|
||||
pinPath := fmt.Sprintf(c.ledPath, pin)
|
||||
fi, e := sysfs.OpenFile(pinPath, os.O_WRONLY|os.O_APPEND, 0666)
|
||||
defer fi.Close()
|
||||
|
|
Loading…
Reference in New Issue