Skip to content

Instantly share code, notes, and snippets.

@abackstrom
Created February 24, 2018 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abackstrom/6b1c23a999b1dd3bff61dce439cf977d to your computer and use it in GitHub Desktop.
Save abackstrom/6b1c23a999b1dd3bff61dce439cf977d to your computer and use it in GitHub Desktop.
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