Hey guys,
I know that the subject about this problem is recurrent but I didn't find a solution to my problem.
I want to "stream" picture to my Rainbowduino which is link with my Arduino UNO. For that, I use Processing to analyse et getPixel RGB value for each 8x8 pixel of my image. Till this, there is no matter.
Now I have to send all these datas to my Arduino and there is the matter. I didn't manage to send well my data one per one to Arduino. It's like Arduino didn't understand which Processing data corresponding to Arduino Data.
Here is my code, maybe you could help me to this very newbie problem ![]()
Arduino Code :
i#include <Rainbowduino.h>
int xWidth;
int yHeight;
int color;
void setup(){
Serial.begin(9600);
Rb.init();
}
void loop(){
if (Serial.available() >= 3){
xWidth = Serial.read();
yHeight = Serial.read();
color = Serial.read();
//Serial.println (xWidth);
//Serial.println(yHeight);
Serial.println(color);
Rb.setPixelXY(xWidth, yHeight, color, color, color);
} else {
Serial.println("Nothing is detected");
for (int i = 0; i < 8; i++){
for(int j = 0; j < 8; j++){
Rb.setPixelXY(i, j, 0, 0, 0);
}
}
}
delay(2000);
}
Processing Code :
import processing.serial.*;
Serial myPort;
PImage myImage;
int loc = 0;
int xWidth = 0;
int yHeight = 0;
void setup(){
size(8, 8);
myImage = loadImage("FLV.png");
println(Serial.list());
String portName = Serial.list()[2];
myPort = new Serial(this, portName, 9600);
}
void draw(){
image(myImage, 0, 0);
for(int x = 0; x < myImage.width; x++){
for(int y = 0; y < myImage.height; y ++){
loc = y + x*height;
xWidth = x;
yHeight = y;
String red = hex((int)red(myImage.get(x,y)));
String green = hex((int)green(myImage.get(x,y)));
String blue = hex((int)blue(myImage.get(x,y)));
//println("A la position ", loc, " R = ", red, ", G : ", green, ", B : ", blue);
myPort.write(xWidth);
println("x: ", xWidth, "sent");
myPort.write(yHeight);
println("y : ", yHeight, "sent");
myPort.write(red);
println("color : ", red, "sent");
delay(2000);
if (loc == 63){
println("--- FINISH ---");
}
}
}
}
Thank you so much
!
Edit : I fixed the code problem. Thanks Robin !