Exemplo n.º 1
0
func outputLoop(sig chan struct{}) {
	pin, err := rpi.OpenPin(rpi.GPIO17, gpio.ModeOutput)
	if err != nil {
		log.Fatalf("Can't open pin: %s", err.Error())
	}
	defer pin.Close()
	pin.Set()
	for {
		select {
		case <-sig:
			pin.Clear()
			time.Sleep(time.Millisecond * 300)
			pin.Set()
			time.Sleep(time.Millisecond * 300)
		}
	}
}
Exemplo n.º 2
0
func init() {
	openGarage = openWithGPIO

	mustPin := func(num int, mode gpio.Mode) gpio.Pin {
		pin, err := rpi.OpenPin(num, mode)
		if err != nil {
			log.Fatal("error opening pin %d for %v: %v", num, mode, err)
		}
		return pin
	}
	red = mustPin(rpi.GPIO23, gpio.ModeOutput)      // red blinky I'm-alive LED
	yellow = mustPin(rpi.GPIO22, gpio.ModeOutput)   // yellow while-pressed LED
	open = mustPin(rpi.GPIO_P1_12, gpio.ModeOutput) // to make the MOSFET close the garage circuit
	button = mustPin(rpi.GPIO25, gpio.ModeInput)    // button to toggle garage now

	if err := button.BeginWatch(gpio.EdgeBoth, onButtonUpDown); err != nil {
		log.Fatalf("button BeginWatch: %v", err)
	}
	go blinkRedHealthy()
	go waitForButtonPress()
}