Created
November 14, 2012 01:48
-
-
Save eikeon/4069729 to your computer and use it in GitHub Desktop.
blink via golang on beablebone
This file contains 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
package main | |
import ( | |
"log" | |
"os" | |
"time" | |
) | |
func setLed(led string, value []byte) { | |
file, err := os.OpenFile(led+"/brightness", os.O_WRONLY, 0666) | |
if err != nil { | |
log.Fatal(err) | |
} | |
file.Write(value) | |
file.Close() | |
} | |
func blink(led string) { | |
setLed(led, []byte("1")) | |
time.Sleep(10 * time.Millisecond) | |
setLed(led, []byte("0")) | |
} | |
func main() { | |
d := 5 | |
t1 := time.NewTicker(time.Duration(d) * time.Second / 2) | |
t2 := time.NewTicker(time.Duration(d) * time.Second / 3) | |
t3 := time.NewTicker(time.Duration(d) * time.Second / 5) | |
for { | |
select { | |
case <-t1.C: | |
go blink("/sys/devices/platform/leds-gpio/leds/beaglebone::usr1") | |
case <-t2.C: | |
go blink("/sys/devices/platform/leds-gpio/leds/beaglebone::usr2") | |
case <-t3.C: | |
go blink("/sys/devices/platform/leds-gpio/leds/beaglebone::usr3") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment