Skip to content

Instantly share code, notes, and snippets.

@z3a
Created October 31, 2013 19:24
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 z3a/7255345 to your computer and use it in GitHub Desktop.
Save z3a/7255345 to your computer and use it in GitHub Desktop.
import processing.serial.*;
//http://forum.arduino.cc/index.php/topic,39922.0.html
PImage img;
int x = 0;
float r,g,b,bright;
Serial myPort;
byte[] column = new byte[16]; //var para guardar las lecturas de la img
void setup() {
size(640, 360);
img = loadImage("moonwalk.jpg");
//lo del serial
println(Serial.list());
//OJO: seleccionar el puerto adecuado
myPort = new Serial(this, Serial.list()[0], 115200);
}
//funcion que recibe un array con los datos de los pixeles
//los envia por el serial
void sendData(byte[] data){
myPort.write("<"); // caracter de inicio
myPort.write(data);
myPort.write(">"); // caraceter de finalizacion
}
void draw() {
}
void readValues(){
background(120);
loadPixels();
img.loadPixels();
for(int y = 0; y < height; y++){
int loc = x+y*width;
r = red(img.pixels[loc]);
g = green(img.pixels[loc]);
b = blue(img.pixels[loc]);
bright = brightness(color(r,g,b));
//llenamos el array con los datos de la img
for(int i= 0; i<column.length; i++){
column[i] = byte(bright);
}
println(column);
//enviamos por el puerto serial
sendData(column);
//println("r: "+r+" g: "+g+" b: "+b+" bright: "+bright);
pixels[loc] = color(r,g,b);
}
updatePixels();
}
void keyPressed(){
println("----------------------------");
readValues();
println("============================");
if(x<width-1){
x++;
} else {
x = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment