mirror of
https://github.com/danbulant/colors
synced 2026-06-20 06:41:10 +00:00
28 lines
No EOL
800 B
TypeScript
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}`);
|
|
} |