Created
October 31, 2013 19:24
-
-
Save z3a/7255345 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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