Skip to content

Instantly share code, notes, and snippets.

@pelikhan
Last active September 12, 2016 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pelikhan/267c551bbd0972fff372f4f19f882a02 to your computer and use it in GitHub Desktop.
Save pelikhan/267c551bbd0972fff372f4f19f882a02 to your computer and use it in GitHub Desktop.
bycicle neo-lights
// road bike neopixel animation
const strip = neopixel.create(DigitalPin.P0, 60, NeoPixelMode.RGB)
const back = strip.range(0, 10)
const mid = strip.range(10, 40)
const head = strip.range(50, 10)
// global variable to keep track of the animation
let running = false
function run() {
// only start once
if (running) {
return;
}
// setup strip
running = true
clear()
back.setPixelColor(0, NeoPixelColors.Red)
head.setPixelColor(0, NeoPixelColors.White)
mid.range(0, 20).showRainbow()
control.inBackground(() => {
while (running) {
back.rotate()
mid.rotate()
head.rotate()
strip.show()
led.toggle(Math.random(5), Math.random(5))
basic.pause(10)
}
// turn off all to save power
clear()
})
}
function clear() {
strip.clear()
strip.show()
basic.clearScreen()
}
// A --> start running
input.onButtonPressed(Button.A, run)
// B --> stop
input.onButtonPressed(Button.B, () => {
running = false
})
// always start
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment