예제 #1
0
파일: pullup.go 프로젝트: gonutz/gopio
package main

import (
	"fmt"
	"github.com/gonutz/gopio"
	"os"
)

var (
	// Use mcu pin 22, corresponds to GPIO3 on the pi
	pin = gopio.Pin(22)
)

func main() {
	// Open and map memory to access gpio, check for errors
	if err := gopio.Open(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	// Unmap gpio memory when done
	defer gopio.Close()

	// Pull up and read value
	pin.PullUp()
	fmt.Printf("PullUp: %d\n", pin.Read())

	// Pull down and read value
	pin.PullDown()
	fmt.Printf("PullDown: %d\n", pin.Read())
예제 #2
0
파일: blinker.go 프로젝트: gonutz/gopio
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/gonutz/gopio"
	"os"
	"time"
)

var (
	// Use mcu pin 10, corresponds to physical pin 19 on the pi
	pin = gopio.Pin(10)
)

func main() {
	// Open and map memory to access gpio, check for errors
	if err := gopio.Open(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	// Unmap gpio memory when done
	defer gopio.Close()

	// Set pin to output mode
	pin.Output()