ebike lighting system
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
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