Skip to content

Instantly share code, notes, and snippets.

@pelikhan
Created September 19, 2016 16:29
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/3030512eac77c2321198daf2f40e2edb to your computer and use it in GitHub Desktop.
Save pelikhan/3030512eac77c2321198daf2f40e2edb to your computer and use it in GitHub Desktop.
ebike lighting system
let strip = neopixel.create(DigitalPin.P0, 120, NeoPixelMode.RGB)
// ranges
let tails =[strip.range(0, 5), strip.range(115, 5)]
let heads =[strip.range(55, 5), strip.range(60, 8)]
let sides =[strip.range(5, 50), strip.range(68, 47)]
// reseting the lights on the strip
function setupLights() {
strip.clear()
// back headlights: 1 red LED rotating
// head light: 1 white LED rotating
// side lights: 5 LED travelling
for (let i = 0; i < 2; i++) {
tails[i].setPixelColor(0, NeoPixelColors.Red)
heads[i].setPixelColor(0, NeoPixelColors.White);
for (let j = 0; j < 5; j++) {
sides[i].setPixelColor(j, NeoPixelColors.Green);
}
}
}
setupLights()
basic.forever(() => {
// just for kicks
led.toggle(Math.random(5), Math.random(5))
// rotate all ranges
tails[0].rotate(1)
tails[1].rotate(-1)
heads[0].rotate(-1)
heads[1].rotate(1)
sides[0].rotate(-1)
sides[1].rotate(1)
strip.show()
// handle acceleration bump
if (input.acceleration(Dimension.Strength) > 1300) {
while (input.acceleration(Dimension.Strength) > 1100) {
strip.showColor(NeoPixelColors.Red)
basic.pause(150)
strip.clear()
strip.show()
basic.pause(100)
}
setupLights()
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment