Created
July 25, 2014 05:09
-
-
Save chrissnell/1134b7687e5940aeba11 to your computer and use it in GitHub Desktop.
Toggler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A little blurb I wrote to toggle something on and off, always making sure to toggle off before shutdown | |
toggle := make(chan bool, 1) | |
outputPin, err := hwio.GetPinWithMode(pin, hwio.OUTPUT) | |
if err != nil { | |
log.Printf("Error getting GPIO pin: %v\n", err) | |
} | |
go func() { | |
for { | |
timer := time.NewTimer(time.Second * 3) | |
<-timer.C | |
fmt.Println("Toggling on") | |
toggle <- true | |
timer2 := time.NewTimer(time.Second * 3) | |
<-timer2.C | |
fmt.Println("Toggling off") | |
toggle <- false | |
} | |
}() | |
for { | |
select { | |
case <-shutdownFlight: | |
fmt.Println("--- Break") | |
hwio.DigitalWrite(outputPin, hwio.LOW) | |
hwio.CloseAll() | |
fmt.Println("Closed all pins") | |
shutdownComplete <- true | |
break | |
case t := <-toggle: | |
aprsMessage <- "Preparing to cutdown in 30 sec" | |
fmt.Printf("Toggling: %v\n", t) | |
if t { | |
hwio.DigitalWrite(outputPin, hwio.HIGH) | |
} else { | |
hwio.DigitalWrite(outputPin, hwio.LOW) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment