Skip to content

Instantly share code, notes, and snippets.

@raveren
Created June 16, 2022 14:55
Show Gist options
  • Save raveren/b786c0d40b396528f62020ddbf777b2c to your computer and use it in GitHub Desktop.
Save raveren/b786c0d40b396528f62020ddbf777b2c to your computer and use it in GitHub Desktop.
function change_colors () {
h += 1
if (h > 360) {
h = 0
}
strip.showColor(neopixel.hsl(h, l, s))
strip2.showColor(neopixel.hsl(360 - h, l, s))
basic.pause(10)
}
function flags () {
for (let index = 0; index < 2; index++) {
for (let index = 0; index < 23; index++) {
push_color(1, NeoPixelColors.Yellow)
}
for (let index = 0; index < 23; index++) {
push_color(1, blue_color)
}
}
for (let index = 0; index < 9; index++) {
push_color(1, NeoPixelColors.Yellow)
}
for (let index = 0; index < 9; index++) {
push_color(1, NeoPixelColors.Green)
}
for (let index = 0; index < 9; index++) {
push_color(1, NeoPixelColors.Red)
}
for (let index = 0; index < 23; index++) {
push_color(1, blue_color)
}
}
input.onButtonPressed(Button.A, function () {
mode += 1
if (mode >= 2) {
mode = 0
}
})
input.onButtonPressed(Button.B, function () {
l = randint(0, 100)
s = randint(0, 100)
})
let s = 0
let l = 0
let h = 0
let blue_color = 0
let strip: neopixel.Strip = null
let strip2: neopixel.Strip = null
let mode = 0
h = 0
l = randint(0, 100)
s = randint(0, 100)
blue_color = neopixel.hsl(260, 70, 40)
function push_color(m: number, color: NeoPixelColors) {
if(mode !== m) {
return
}
strip.rotate(1)
strip.setPixelColor(0, color)
strip.show()
strip2.rotate(1)
strip2.setPixelColor(0, color)
strip2.show()
basic.pause(50)
}
strip = neopixel.create(DigitalPin.P0, 23, NeoPixelMode.RGB)
strip2 = neopixel.create(DigitalPin.P1, 23, NeoPixelMode.RGB)
mode = 0
basic.forever(function () {
if (mode == 1) {
flags()
} else {
if (mode == 0) {
change_colors()
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment