// check if button is pressed func buttonHandler(p gpio.Pin) { for { if p.Get() { ctrlChan <- true } time.Sleep(150 * time.Millisecond) } }
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) } } } }