Skip to content

Instantly share code, notes, and snippets.

@asukakenji
Last active October 11, 2016 21:11
Show Gist options
  • Save asukakenji/07f8761a67427b6a91bea9303bbe3eab to your computer and use it in GitHub Desktop.
Save asukakenji/07f8761a67427b6a91bea9303bbe3eab to your computer and use it in GitHub Desktop.
func (bt *BlinkyTape) playPattern(p Pattern, delay time.Duration) {
bt.clear()
L:
for _, frame := range p {
bt.setFrame(frame)
if err := bt.render(); err != nil {
log.Fatalf("render error: %s\n", err)
}
timer := timer.NewTimer(delay)
timer.Start()
stop := bt.stop
pause := bt.pause
resume := nil
timerC := nil
select {
case <-stop:
stop <- struct{}{}
break L
case <-pause:
if paused := timer.Pause(); paused != false {
// stop = bt.stop
pause = nil
resume = bt.resume
timerC = nil
}
case <-resume:
if started := timer.Start(); started != false {
// stop = bt.stop
pause = nil
resume = nil
timerC = timer.C
}
case <-timerC:
continue L
}
}
bt.next <- struct{}{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment