Created
March 12, 2018 11:41
-
-
Save yratof/1c78999c93e92fb4802d3532b09e5254 to your computer and use it in GitHub Desktop.
micro:bit light looping
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 pos = 0 | |
let colour = 0 | |
let len = 0 | |
let stretch = 0 | |
let item: neopixel.Strip = null | |
let LED_Count = 0 | |
LED_Count = 90 | |
item = neopixel.create(DigitalPin.P0, LED_Count, NeoPixelMode.RGB) | |
item.clear() | |
item.easeBrightness() | |
stretch = 15 | |
len = LED_Count - stretch | |
basic.forever(() => { | |
item.clear() | |
for (let index = 0; index <= LED_Count + stretch / 1; index++) { | |
if (index >= LED_Count) { | |
index = index - LED_Count | |
} | |
item.show() | |
for (let list = 0; list <= stretch / 2; list++) { | |
colour = neopixel.rgb(255 - list / 2, 10 * (list / 2), 30 * (list * 2)) | |
item.setPixelColor(index - list, colour) | |
} | |
colour = neopixel.rgb(255, 30, 15) | |
item.setPixelColor(index, colour) | |
item.setPixelColor(index + 1, colour) | |
item.setPixelColor(index - 1, colour) | |
item.setPixelColor(index + (stretch + 1), neopixel.rgb(0, 0, 0)) | |
pos = index - (stretch + 1) | |
if (0 > pos) { | |
pos = pos + LED_Count | |
} | |
item.setPixelColor(pos, neopixel.rgb(0, 0, 0)) | |
item.show() | |
if (index <= 30) { | |
basic.pause(20) | |
} | |
basic.pause(20) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment