Skip to content

Instantly share code, notes, and snippets.

@cat-haines
Last active December 14, 2015 02:29
Show Gist options
  • Save cat-haines/5013682 to your computer and use it in GitHub Desktop.
Save cat-haines/5013682 to your computer and use it in GitHub Desktop.
Electric Imp code to go with Electric_Imp_Example repository. Passes RGB json object to Electric_Imp_Example API.
local redPot = hardware.pin5;
local greenPot = hardware.pin7;
local bluePot = hardware.pin8;
local red = 0;
local green = 0;
local blue = 0;
local redPort = OutputPort("red");
local greenPort = OutputPort("green");
local bluePort = OutputPort("blue");
local jsonOutputPort = OutputPort("json");
function readPots()
{
red = 255 - (redPot.read() / 65535.0 * 255.0).tointeger();
green = 255 - (greenPot.read() / 65535.0 * 255.0).tointeger();
blue = 255 - (bluePot.read() / 65535.0 * 255.0).tointeger();
redPort.set(red);
greenPort.set(green);
bluePort.set(blue);
jsonOutputPort.set("{ 'r':" + red + ", 'g':" + green + ", 'b':" + blue + " }");
imp.wakeup(0.25, readPots);
}
hardware.pin5.configure(ANALOG_IN);
hardware.pin7.configure(ANALOG_IN);
hardware.pin8.configure(ANALOG_IN);
imp.configure("RGB Imp", [], [redPort, greenPort, bluePort, jsonOutputPort]);
readPots();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment