Created
June 16, 2018 10:58
-
-
Save jamesbulpin/62f4afd3637167035ad8fb2e681e30c5 to your computer and use it in GitHub Desktop.
Demo program for connecting an LED-illuminated Minifig to CheerLights
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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