Last active
September 12, 2016 04:59
-
-
Save pelikhan/267c551bbd0972fff372f4f19f882a02 to your computer and use it in GitHub Desktop.
bycicle neo-lights
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
// 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