go-rpio/examples/blinker/blinker.go
Aleksei Fedotov b79c58a7a3 Use physical PIN number in blinker example.
The behavior of the test is not changed, now it hides BCM bin number and
used physical PIN number.
2020-04-26 18:54:01 +02:00

46 lines
764 B
Go

/*
A blinker example using go-rpio library.
Requires administrator rights to run
Toggles a LED on physical pin 19 (mcu pin 10)
Connect a LED with resistor from pin 19 to ground.
*/
package main
import (
"fmt"
"github.com/stianeikeland/go-rpio"
"os"
"time"
)
func main() {
// Open and map memory to access gpio, check for errors
if err := rpio.Open(); err != nil {
fmt.Println(err)
os.Exit(1)
}
// Unmap gpio memory when done
defer rpio.Close()
// Use physical pin 19, mappings to GPIO numers are done internally
pin, err := rpio.GetBoardPin(19)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// Set pin to output mode
pin.Output()
// Toggle pin 20 times
for x := 0; x < 20; x++ {
pin.Toggle()
time.Sleep(time.Second / 5)
}
}