Skip to content

Instantly share code, notes, and snippets.

@jkuip
Created February 21, 2017 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkuip/c05f309900b63542d68b4f87fe5506e4 to your computer and use it in GitHub Desktop.
Save jkuip/c05f309900b63542d68b4f87fe5506e4 to your computer and use it in GitHub Desktop.
/* PARTICLE CODE */
// This #include statement was automatically added by the Particle IDE.
#include <rgb-controls.h>
using namespace RGBControls;
Color red = Color(255, 0, 0);
Color green = Color(0, 255, 0);
Color blue = Color(0, 0, 255);
Led led(D0, D1, D2, false);
int r,g,b;
void setup() {
Particle.function("led", ledControl);
led.setColor(blue);
}
void loop() {
// do nothing
}
int ledControl(String command)
{
int i = command.indexOf(",");
int j = command.indexOf(",",i+1);
r = command.substring(0,i).toInt();
g = command.substring(i+1, j).toInt();
b = command.substring(j+1, command.length()).toInt();
led.setColor(Color(r,g,b));
return 1;
}
/* P5JS CODE */
var img;
var c;
function preload()
{
img = loadImage("YOURIMAGE.jpg");
}
function setup() {
createCanvas(640, 425);
c = color(255);
}
function draw() {
image(img, 0, 0);
strokeWeight(3);
stroke(255);
fill(c);
rect(25, 25, 25, 25);
}
function mousePressed()
{
c = get(mouseX, mouseY);
var rgbValue = c[0] + "," + c[1] + "," + c[2];
print(rgbValue);
var particle = new Particle();
particle.callFunction({
deviceId: 'YOURDEVICEID',
name: 'led',
argument: rgbValue,
auth: 'YOURAUTHVALUE'
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment