Skip to content

Instantly share code, notes, and snippets.

@jaeh
Created April 18, 2017 18:37
Show Gist options
  • Save jaeh/ab5b0b61cbf0495585397cf2e4f27441 to your computer and use it in GitHub Desktop.
Save jaeh/ab5b0b61cbf0495585397cf2e4f27441 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const ledCount = process.argv[2] || 1;
const colorName = process.argv[3] || 'white';
const interval = process.argv[4] === 'interval';
const intervalStepDuration = process.argv[5] || 1000;
function getColors() {
const colors = {
white: [255, 255, 255],
red: [255, 0, 0],
green: [0, 255, 0],
blue: [0, 0, 255],
// turquoise: [47, 179, 179],
// pink: [255, 140, 220],
// purple: [190, 40, 170],
greenblue: [0, 255, 255],
redblue: [255, 0, 255],
redgreen: [255, 255, 0],
// test1: [55, 55, 55],
// test2: [100, 100, 100],
black: [0, 0, 0],
};
let color = colors[colorName] || [255, 255, 255];
if (colorName === 'random') {
const colorNames = Object.keys(colors);
const idx = Math.floor(Math.random() * (colorNames.length - 1.00001))
color = colors[colorNames[idx]];
}
else if (parseInt(colorName) === parseInt(colorName)) {
console.log('setting color', colorName)
color = [colorName, process.argv[4] || colorName, process.argv[5] || colorName];
}
let colorArray = [];
for (let i = 0; i < ledCount; i++) {
colorArray = colorArray.concat(color);
}
console.log(`painting ${ledCount} leds with value: ${color} and ${colorArray.length} channels`);
return colorArray;
}
const options = [
{
host: '10.0.0.2', // (Default '255.255.255.255')
port: 6454, // (Default 6454)
refresh: 4000, //(millisecond interval for sending unchanged data to the Art-Net node. Default 4000)
// iface '', // (optional string IP address - bind udp socket to specific network interface)
sendAll: true, //(sends always the full DMX universe instead of only changed values. Default false)
},
{
host: '10.0.0.3', // (Default '255.255.255.255')
port: 6454, // (Default 6454)
refresh: 4000, //(millisecond interval for sending unchanged data to the Art-Net node. Default 4000)
// iface '', // (optional string IP address - bind udp socket to specific network interface)
sendAll: true, //(sends always the full DMX universe instead of only changed values. Default false)
},
{
host: '10.0.0.4', // (Default '255.255.255.255')
port: 6454, // (Default 6454)
refresh: 4000, //(millisecond interval for sending unchanged data to the Art-Net node. Default 4000)
// iface '', // (optional string IP address - bind udp socket to specific network interface)
sendAll: true, //(sends always the full DMX universe instead of only changed values. Default false)
}];
const artnet = require('artnet')
const artnets = [
artnet(options[0]),
artnet(options[1]),
artnet(options[2]),
]
const ips = ['10.0.0.2', '10.0.0.3', '10.0.0.4'];
const numOfUniverses = 36;
let startchannel = 1;
function setArtnet() {
const colorArray = getColors();
// for (let j = 0; j < ips.length - 1; j++) {
for (let i = 0; i < numOfUniverses; i++) {
artnets[0].set(i, startchannel, colorArray, function (err, res) {
// console.log(`artnet has been set
// universe ${i}
// startchannel ${startchannel}
// errors: ${err}
// result: ${res}
// `);
// if (!interval) {
// artnet.close();
// }
});
}
// }
}
if (!interval) {
setArtnet();
}
else {
setInterval(setArtnet, intervalStepDuration);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment