Skip to content

Instantly share code, notes, and snippets.

@matthewfl
Created February 13, 2012 06:17
Show Gist options
  • Save matthewfl/1814204 to your computer and use it in GitHub Desktop.
Save matthewfl/1814204 to your computer and use it in GitHub Desktop.
display the image for a cmucam that is directly connected
import processing.serial.*;
Serial cmucam;
void setup () {
cmucam = new Serial(this, "/dev/tty.usbserial-A400C1Q8", 115200);
size(200, 200);
delay(1500);
cmucam.write("RS\r");
delay(150);
frameRate(4);
}
void draw () {
//byte buffer[1024*50];
background(123);
int[] buffer = new int[15];
int x=0;
int y=-1;
int px=0;
cmucam.write("SF\r");
while(true) {
while(cmucam.available()<1);
int read = cmucam.read();
if(read == 1) {
while(cmucam.read() != 2);
}else if(read == 2) {
x=0;
y++;
}else if(read == 3) {
break;
}else{
buffer[px++] = read;
if(px==3) {
px=0;
// println(buffer[0] + " " +buffer[1] + " " + buffer[2]);
set(x++,y,color(buffer[0], buffer[1], buffer[2]));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment