Hello.
I'm trying to build a project where in a acrylic pillar will change it's color according to the ambiance.
Now to do that I've written (With taking some help) a program in Processing which would send serially the R G B values from the live camera video.
(The Processing sketch is attached below)
here's the snippet from the processing sketch which sends R G B Values to the serial port.
myPort.write(r + "," + g + "," + b + ".");
code:
import processing.video.*;
import processing.serial.*;
Serial myPort;
Capture video;
float m,r,g,b;
int loc;
boolean R = false;
PFont f;
void setup() {
size(640,480);
myPort = new Serial(this, "COM11", 9600);
video = new Capture(this,width,height,15);
f = createFont("Haettenschweiler",12);
}
void draw() {
if (video.available()) {
video.read();
}
image(video,0,0);
for (int i = 0; i < video.width; i+=10) {
for (int j = 0; j < video.height; j+=10) {
loc = i + j * width;
color c = video.pixels[loc]; // Get a pixel
r = red(c);
g = green(c);
b = blue(c); // Get the red value
m = map(i, 0, width-50,50, 100);
stroke(255,0,0);
point(m-40,-r/2+height-5);
stroke(0,255,0);
point(m+20,-g/2+height-5);
stroke(0,0,255);
point(m+80,-b/2+height-5);
}
}
textSize(10);
fill(255,0,0);
text(nf(r,2,0),200,height-60);
fill(0,255,0);
text(nf(g,2,0),200,height-45);
fill(0,0,255);
text(nf(b,2,0),200,height-30);
myPort.write(r + "," + g + "," + b + ".");
println(r + "," + g + "," + b);
}
Now I need an Arduino sketch which would utilize this received string to write, with PWM, the RGB LED's Pins Accordingly for according color settings.
I don't know where to start from extracting the string in the Arduino code.
I found a simple RGB control program on web which I'm attaching here(with a bit of my own twitching)
int redPin = 11;
int greenPin = 10;
int bluePin = 9;
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
setColor(255, 0, 0); // red
delay(1000);
setColor(0, 255, 0); // green
delay(1000);
setColor(0, 0, 255); // blue
delay(1000);
setColor(255, 255, 0); // yellow
delay(1000);
setColor(80, 0, 80); // purple
delay(1000);
setColor(0, 255, 255); // aqua
delay(1000);
}
void setColor(int red, int green, int blue)
{
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
void serialEvent() {
while (Serial.available())
{
//from here on I need some help
...
}
I got this reply here :
http://forum.arduino.cc/index.php?topic=185841.new;topicseen#new
Can anybody help me here?