Skip to content

Instantly share code, notes, and snippets.

@pelikhan pelikhan/main.ts
Last active Sep 12, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.