Beispiel #1
0
// check if button is pressed
func buttonHandler(p gpio.Pin) {
	for {
		if p.Get() {
			ctrlChan <- true
		}
		time.Sleep(150 * time.Millisecond)
	}
}
Beispiel #2
0
func dance(pin gpio.Pin, ctrlChan chan bool) {
	enabled := false
	for {
		select {
		case val := <-ctrlChan:
			fmt.Printf("dancing? %+v\n", val)
			enabled = val
		default:
			if enabled {
				pin.Set()
				time.Sleep(500 * time.Millisecond)
				pin.Clear()
				time.Sleep(500 * time.Millisecond)
			}
		}
	}
}