2013-07-30 19:25:43 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-08-19 03:39:30 +02:00
|
|
|
"github.com/stianeikeland/go-rpio/v4"
|
2013-07-30 19:25:43 +02:00
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// Use mcu pin 22, corresponds to GPIO3 on the pi
|
|
|
|
pin = rpio.Pin(22)
|
|
|
|
)
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
// Pull up and read value
|
|
|
|
pin.PullUp()
|
2019-11-28 20:39:02 +01:00
|
|
|
fmt.Printf("PullUp: %d, %d\n", pin.Read(), pin.ReadPull())
|
2013-07-30 19:25:43 +02:00
|
|
|
|
|
|
|
// Pull down and read value
|
|
|
|
pin.PullDown()
|
2019-11-28 20:39:02 +01:00
|
|
|
fmt.Printf("PullDown: %d, %d\n", pin.Read(), pin.ReadPull())
|
2013-07-30 19:25:43 +02:00
|
|
|
|
|
|
|
}
|