Created
February 24, 2018 18:19
-
-
Save abackstrom/6b1c23a999b1dd3bff61dce439cf977d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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