Created
January 22, 2019 01:29
-
-
Save nbogie/c0c677096443644d2af169dad901c453 to your computer and use it in GitHub Desktop.
simple microbit zip halo / neopixel program to spin a light around when the device is shaken
This file contains hidden or 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
let factor2 = 0 | |
let strip: neopixel.Strip = null | |
let maxNeighbourBrightness = 0 | |
let pxPos = 0 | |
let maxBrightness = 0 | |
let factor = 0 | |
let fPos = 0 | |
let braking = 0 | |
let accel = 0 | |
let speed = 0 | |
input.onGesture(Gesture.Shake, function () { | |
speed += 0.5 | |
}) | |
speed = 0 | |
accel = 0.002 | |
braking = 0.002 | |
factor = 0 | |
maxBrightness = 150 | |
maxNeighbourBrightness = maxBrightness * 1 | |
strip = neopixel.create(DigitalPin.P0, 24, NeoPixelMode.RGB) | |
strip.clear() | |
strip.show() | |
basic.forever(function () { | |
if (input.buttonIsPressed(Button.A)) { | |
speed += accel | |
} else { | |
speed += 0 - braking | |
} | |
if (speed < 0) { | |
speed = 0 | |
} | |
fPos += speed | |
if (fPos >= 23) { | |
fPos += 0 - 23 | |
} | |
pxPos = Math.floor(fPos) | |
strip.clear() | |
strip.setBrightness(100) | |
strip.setPixelColor(pxPos, NeoPixelColors.Blue) | |
factor2 = fPos - pxPos | |
if (pxPos > 0) { | |
strip.setBrightness((1 - factor2) * maxNeighbourBrightness) | |
strip.setPixelColor(pxPos - 1, NeoPixelColors.Blue) | |
} | |
if (pxPos < 23) { | |
strip.setBrightness(factor2 * maxNeighbourBrightness) | |
strip.setPixelColor(pxPos + 1, NeoPixelColors.Blue) | |
} | |
strip.show() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment