Having issues pixelating a video with Arduino input

edited February 2016 in Arduino

I'm trying to create a pixelated video where the greater the distance from the arduino distance sensor (4 pin) the greater the size of pixels and vice versa. However so far I can run both and hear the audio playing but no video appears in processing window. I know that Processing is receiving the right data from arduino because it prints correctly in the console.

Arduino code int trigger=7; int echo=6; long time=0; long dist=0;

void setup()
{
Serial.begin (9600);


pinMode(trigger, OUTPUT); pinMode(echo, INPUT);
}


void loop()
{
digitalWrite(trigger, LOW); delay(5); digitalWrite(trigger, HIGH); delay(10); digitalWrite(trigger, LOW); time = pulseIn(echo, HIGH);
dist = (time/2) / 29.1;

if (
Serial.println(dist); 



delay(1000); 
}

Processing Code import processing.serial.*; import processing.video.*;

int numPixelsWide, numPixelsHigh;
int blockSize = 0;
Movie mov;
color movColors[];

Serial myPort;  // Create object from Serial class
String val;     // Data received from the serial port

void setup() {

  size(1200,700);

  noStroke();
  mov = new Movie(this, "MVI_3468.MOV");
  mov.loop();


  //println(Serial.list());
  String portName = Serial.list()[7]; //change the 0 to a 1 or 2 etc. to match your port
  myPort = new Serial(this, portName, 9600); 

}

void draw()
{
  if ( myPort.available() > 0) 
  {  // If data is available,
  val = myPort.readStringUntil('\n');         // read it and store it in val
  } 
  println(val); //print it out in the console

  if (val == null) {}

  else {
     blockSize = int(val);
  }


  if (blockSize == 0)
  {}

 else{

   //println(blockSize);

  numPixelsWide = width / blockSize;
  numPixelsHigh = height / blockSize;

  movColors = new color[numPixelsWide * numPixelsHigh];



   if (mov.available() == true) {
    mov.read();
    mov.loadPixels();
    int count = 0;
    for (int j = 0; j < numPixelsHigh; j++) {
      for (int i = 0; i < numPixelsWide; i++) {
        movColors[count] = mov.get(i*blockSize, j*blockSize);
        count++;
      }
    }
  }

  background(255);
  for (int j = 0; j < numPixelsHigh; j++) {
    for (int i = 0; i < numPixelsWide; i++) {
      fill(movColors[j*numPixelsWide + i]);
      rect(i*blockSize, j*blockSize, blockSize, blockSize);
    }
  }
 }
}

Any help would be welcomed, I am new to Processing so forgive me if there are obvious mistakes.

Sign In or Register to comment.