Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demo program for connecting an LED-illuminated Minifig to CheerLights
var SerialPort = require("serialport");
var tinycolor2 = require("tinycolor2");
var request = require('request');
var portdev = "/dev/ttyACM0";
var port = new SerialPort(portdev, {
baudRate: 9600,
});
port.on('error', function(err) {
console.log('Error: ', err.message);
})
port.on('data', function (data) {
console.log('Data: ' + data);
});
setInterval(function() {
request('http://api.thingspeak.com/channels/1417/field/2/last.json', { json: true }, (err, res, body) => {
if (err) { return console.log(err); }
var c = tinycolor2(body.field2).toRgb();
var r = c.r;
var g = c.g;
var b = c.b;
var x = "COLOR " + tinycolor2({ r: r, g: g, b: b }).toHexString() + "\n";
port.write(x);
});
}, 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment