colors/index.ts
2021-09-12 21:13:44 +02:00

28 lines
No EOL
800 B
TypeScript

import { JoyStick } from "./joystick";
const devices = await JoyStick.getList();
for(const device of devices) {
const colors = await device.getColors();
const max = await device.getMaxColors();
console.log(`Found device ${device.name}:
Colors:
RED ${colors.red}
GREEN ${colors.green}
BLUE ${colors.blue}
Max colors:
RED ${max.red}
GREEN ${max.green}
BLUE ${max.blue}`)
const newColors = {
red: Math.floor(Math.random() * max.red),
green: Math.floor(Math.random() * max.green),
blue: Math.floor(Math.random() * max.blue),
};
await device.setColors(newColors);
console.log(`
Updated colors:
RED ${newColors.red}
GREEN ${newColors.green}
BLUE ${newColors.blue}`);
}