-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom.js
43 lines (35 loc) · 1.14 KB
/
random.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
/*
Module: Random example
Description: Lights all buttons with random colors every 0.5 seconds
Compatibility: RGB capable Launchpads
WARNING: Do not run if you are sensitive to flashing lights
*/
const _ = require("lodash");
require("@rocketry/core");
require("@rocketry/plugin-node-midi");
const {default: LaunchpadMk2} = require("@rocketry/device-launchpad-mk2");
// Create new launchpad
const launchpad = new LaunchpadMk2();
// Light each button using lodash's simple random function
const lightRandom = function() {
for (const button of launchpad.buttons) {
// All standard color values except off
button.light(_.random(1, 127));
}
};
// Create an interval to do it every 500ms (you can change with a command line argument with the ms to use)
const ms = parseInt(process.argv[2]) || 500;
const interval = setInterval(() => {
lightRandom();
}, ms);
// Cleanup before interupt
console.log("Use `ctrl + c` (interrupt) to reset and exit.");
process.once("SIGINT", () => {
console.log("Exiting...");
// Stop repeating
clearInterval(interval);
// Clear the buttons
launchpad.dark();
// Close the IO to the launchpad
launchpad.close();
});