pxt-calliope/libs/neopixel/neotest.ts

48 lines
1007 B
TypeScript
Raw Normal View History

2016-04-13 07:09:03 +02:00
let strip = neopixel.create(DigitalPin.P0, 24);
2016-04-06 03:21:24 +02:00
let br = 100;
strip.setBrigthness(100);
input.onButtonPressed(Button.B, () => {
br = br + 20;
if (br > 255) {
br = 5;
2016-04-04 02:38:50 +02:00
}
2016-04-06 03:21:24 +02:00
strip.setBrigthness(br);
2016-04-04 02:38:50 +02:00
});
2016-04-06 03:21:24 +02:00
let rotationMode = false;
input.onButtonPressed(Button.A, () => {
rotationMode = !rotationMode;
if (rotationMode) {
basic.showLeds(`
. # # # .
# . . . #
# . . . #
# . . . #
. # # # .
`);
} else {
basic.showLeds(`
. . # . .
. . . # .
# # # # #
. . . # .
. . # . .
`);
2016-04-04 02:38:50 +02:00
}
});
2016-04-06 03:21:24 +02:00
while (true) {
let x = input.acceleration(Dimension.X) / 2
let y = input.acceleration(Dimension.Y) / 2
let z = input.acceleration(Dimension.Z) / 2
if (rotationMode) {
strip.rotate();
} else {
2016-04-13 07:09:03 +02:00
strip.setPixelColor(0, x, y, -z);
2016-04-06 03:21:24 +02:00
strip.shift(1);
2016-04-04 02:38:50 +02:00
}
2016-04-13 07:09:03 +02:00
strip.show();
2016-04-06 03:21:24 +02:00
basic.pause(100);
}