mirror of
https://github.com/stianeikeland/go-rpio.git
synced 2025-02-02 15:30:36 +01:00
Added example program: blinker.go
This commit is contained in:
parent
ce23315e88
commit
df0edecd6c
43
examples/blinker/blinker.go
Normal file
43
examples/blinker/blinker.go
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Use mcu pin 10, corresponds to physical pin 19 on the pi
|
||||||
|
pin = rpio.Pin(10)
|
||||||
|
)
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
// Set pin to output mode
|
||||||
|
pin.Output()
|
||||||
|
|
||||||
|
// Toggle pin 20 times
|
||||||
|
for x := 0; x < 20; x++ {
|
||||||
|
pin.Toggle()
|
||||||
|
time.Sleep(time.Second / 5)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user