-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrememberColors.js
More file actions
executable file
·32 lines (23 loc) · 715 Bytes
/
rememberColors.js
File metadata and controls
executable file
·32 lines (23 loc) · 715 Bytes
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
// by now you can probably see that this is just me having fun :P
import { colors, autoDetect } from '../dist/index.js';
const { colorFromHex, defaultColors } = colors;
const lp = autoDetect();
lp.once('ready', (name) => {
console.log(`Connected to ${name}`);
});
const savedColors = {};
function getColor(note) {
if (!(note in savedColors)) {
const randHex = Math.floor(Math.random() * 16777215).toString(16);
savedColors[note] = colorFromHex(randHex);
}
return savedColors[note];
}
lp.on('buttonDown', (note, value) => {
lp.setButtonColor(note, getColor(note));
});
lp.on('buttonUp', (note, value) => {
setTimeout(() => {
lp.setButtonColor(note, defaultColors.off);
}, 10);
});