-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.js
44 lines (39 loc) · 1.38 KB
/
demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { CreateDevice, Lights } from './dist/main.js';
(async () => {
var Device = await CreateDevice();
const step = 10;
const time = 50;
const offsets = [5, 10];
const offsetsb = [4, 8];
var EndFlag = false;
const loop = async () => {
for (var x = 0; x < 255; x += step) {
if (x > 255) x = 255;
var offset = [x - step * offsets[0], x - step * offsets[1]].map(o => (o < 0 ? 0 : o));
Device.SetColor(Lights.Left, offset[1], 0, 0);
Device.SetColor(Lights.WallLeft, offset[0], 0, 0);
Device.SetColor(Lights.WallCenter, x, 0, 0);
Device.SetColor(Lights.WallRight, offset[0], 0, 0);
Device.SetColor(Lights.Right, offset[1], 0, 0);
await delay(time);
}
for (var x = 255; x > 0; x -= step) {
if (x < 0) x = 0;
var offset = [x + step * offsetsb[0], x + step * offsetsb[1]].map(o => (o > 255 ? 255 : o));
Device.SetColor(Lights.Left, offset[1], 0, 0);
Device.SetColor(Lights.WallLeft, offset[0], 0, 0);
Device.SetColor(Lights.WallCenter, x, 0, 0);
Device.SetColor(Lights.WallRight, offset[0], 0, 0);
Device.SetColor(Lights.Right, offset[1], 0, 0);
await delay(time);
}
};
Device.on('close', () => {
console.log('amBX disconnected!');
EndFlag = true;
});
while (!EndFlag) await loop();
})();
const delay = time => {
return new Promise(res => setTimeout(res, time));
};