Skip to content

Instantly share code, notes, and snippets.

@abackstrom abackstrom/gpio.go
Created Feb 24, 2018

Embed
What would you like to do?
package main
// Pinout https://forums.ni.com/legacyfs/online/202279_Main%20Pinout.png
// Pibrella (Python) https://github.com/pimoroni/pibrella/blob/master/library/pibrella/__init__.py
// go-rpio https://github.com/stianeikeland/go-rpio/blob/master/rpio.go
import (
"fmt"
"github.com/stianeikeland/go-rpio"
"os"
"os/signal"
"time"
)
const (
red = rpio.Pin(27)
yellow = rpio.Pin(17)
green = rpio.Pin(4)
)
func cleanup() {
red.Low()
yellow.Low()
green.Low()
rpio.Close()
}
func setPin(pin rpio.Pin, state bool) {
if state {
pin.High()
} else {
pin.Low()
}
}
func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for range c {
cleanup()
os.Exit(1)
}
}()
if err := rpio.Open(); err != nil {
fmt.Println(err)
os.Exit(1)
}
red.Output()
yellow.Output()
green.Output()
i := 0
for {
i++
setPin(red, i&1 == 1)
setPin(yellow, i>>1&1 == 1)
setPin(green, i>>2&1 == 1)
time.Sleep(time.Second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.