WS2801-Pi
Search…
Example Animation
1
import LedController from 'ws2801-pi';
2
// const LedController = require('ws2801-pi').default;
3
4
const amountOfLedsOnStrip = 100;
5
6
const ledController = new LedController(amountOfLedsOnStrip);
7
8
async function wait(ms) {
9
return new Promise((resolve) => {
10
setTimeout(resolve, ms);
11
});
12
}
13
14
async function animate() {
15
let colors = [
16
{red: 255, green: 0, blue: 0},
17
{red: 0, green: 255, blue: 0},
18
{red: 0, green: 0, blue: 255},
19
{red: 255, green: 255, blue: 0},
20
{red: 255, green: 0, blue: 255},
21
{red: 0, green: 255, blue: 255},
22
{red: 0, green: 0, blue: 0},
23
];
24
25
for (const color of colors) {
26
for (let ledIndex = 0; ledIndex < amountOfLedsOnStrip; ledIndex++) {
27
ledController
28
.setLed(ledIndex, color)
29
.show();
30
31
await wait(30);
32
}
33
34
await wait(300);
35
}
36
}
37
animate();
Copied!
Last modified 1yr ago
Copy link