hello guys
i have a project in mind, its simply an RGB led that simulate the color of any pixels in a specefic image.
it goas as folowing :
1 - picking the color of any pixel in an image by processing
2 - send the RGB values to arduino.
3 - receiving the values by arduino and apply it to the RGB led using analogWrite .
but iam having a problem in sending and receving the values
the problems :
1 - the RGB values that been send via the serial port are wrong and some in minus sign (i checked it
with println)
2 - the RGB doesn't seem to light any color but the greenish ones and also the wrong green
no bluish no redish.
the processing code :
import processing.serial.*;
Serial port;
PImage img;
void setup() {
size(580, 695);
port = new Serial(this, Serial.list()[1], 9600);
img = loadImage("lizard.jpg");
}
void draw() {
image(img, 0, 0);
img.loadPixels();
color c = get(mouseX, mouseY);
float r = red(c);
float g = green(c);
float b = blue(c);
byte out[] = new byte[3];
out[0] = byte(r);
out[1] = byte(g);
out[2] = byte(b);
port.write(out);
println(out);
fill(r, g, b);
noStroke();
rect(20, 20, 50, 50);
fill(255);
text(r, 20, 250);
text(g, 20, 270);
text(b, 20, 290);
}
the arduino code :
int curvalue = 0;
int val[] = {0,0,0} ;
int r = 6;
int g = 5;
int b = 3;
void setup() {
Serial.begin(9600);
pinMode(r,OUTPUT);
pinMode(g,OUTPUT);
pinMode(b,OUTPUT);
}
void loop() {
if (Serial.available() > 0){
int incomingvalue = Serial.read();
val[curvalue] = incomingvalue;
curvalue++;
analogWrite(r,val[0]);
analogWrite(g,val[1]);
analogWrite(b,val[2]);
curvalue = 0;
}
}
}