Choppy video

edited March 2016 in Arduino

Hello,

I am trying to get two videos to cross-fade when connected to a Maxbotix LV-MaxSonarEZ0 sensor. It works, but is very choppy.

Here is the code for the arduino:

const int pwPin = 7;
long pulse, inches, cm;

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

void loop() {
  pinMode(pwPin, INPUT);

  pulse = pulseIn(pwPin, HIGH);
  inches = pulse / 147;

  Serial.write(inches);
  delay(500);
}

Processing Code:

import processing.video.*;
import processing.serial.*;

Movie light; 
Movie fog;
Serial port;
float val;

void setup() {
  size(854, 480);

  //videos
  light = new Movie(this, "ChathamLighthouse.mp4");
  fog = new Movie(this, "SkyFog.mp4");

  fog.loop();
  light.loop();

  //port
  port = new Serial(this, Serial.list()[1], 9600); 
}

void draw() {
  if (0 < port.available()) {  
    val = port.read();            
  }
  float  trans = map(val, 5, 30, 255, 0);
  println(trans);

  noTint();
  image(light, 0, 0, width, height);

  tint(255, trans); 
  image(fog, 0, 0, width, height);
}

void movieEvent(Movie m) {
  m.read();
}

Could it be that my graphics card is not powerful enough to for this project? Or is there something in the code that is making it choppy? I am running the program on my Macbook Air. Here are the specs:

MacBook Air (13-inch, Mid 2011); Processor 1.7 GHz Intel Core i5; Memory 4 GB 1333 MHz DDR3; Intel HD Graphics 3000 384 MB.

Answers

  • decoding and scaling two videos at once probably a bit too much for it.

    try it without all the arduino stuff and rule that out.

  • I've tried it mapping the mouseX coordinate to the alpha channel and it works. I think there is too much data coming into the motion sensor to map it directly. Instead, I am trying to set up conditional statements, so when, for example, a person is 20 inches from the video it fades.

    import processing.video.*;
    import processing.serial.*;
    
    Movie light; 
    Movie water;
    Serial port;
    float val;
    float trans;
    
    void setup() {
      size(854, 480);
      frameRate(25);
    
    //videos
      light = new Movie(this, "ChathamLighthouse_2.mp4");
      water = new Movie(this, "Water.mp4");
    
      water.loop();
      light.loop();
    
      //port
      port = new Serial(this, Serial.list()[1], 9600); 
    }
    
    void draw() {
      if (0 < port.available()) {  
        val = port.read();            
      }
      println(val);
    
    if (val <= 20) {
      trans += 1;
    }
      noTint();
      image(light, 0, 0, width, height);
    
      tint(255, trans); 
      image(water, 0, 0, width, height);
    }
    
    void movieEvent(Movie m) {
      m.read();
    }
    

    However, I don't want it to fade completely, but just make it semi-transparent. Is there a way to increase the alpha channel value, but then get it to stop at particular number like 100?

  • It worked — thank you.

    However, now I am getting erratic readings from the serial port. It is reading accurately through the Arduino serial monitor, but in processing I get a loop of specific numbers that do not correspond to the sensor. This continues even when I disconnect the Arduino.

    Here is the code:

    import processing.video.*;
    import processing.serial.*;
    
    //variables
    Movie light; 
    Movie water;
    Serial port;
    float val;
    float trans;
    float alpha;
    
    void setup() {
      size(854, 480);
      frameRate(25);
    
      //videos
      light = new Movie(this, "ChathamLighthouse_2.mp4");
      water = new Movie(this, "Water.mp4");
    
      water.loop();
      light.loop();
    
      //port
      String portName = Serial.list()[1];
      port = new Serial(this, portName, 9600);
    }
    
    void draw() {
      if (0 < port.available()) {  
        val = port.read();
      }
      print(val);
      print("in");
      println();
    
      if (val <= 5 && trans >= 200) {
        alpha += 1;
        trans = constrain(alpha, 201, 255);
      } else if (val <= 10 && trans >= 100) {
        alpha += 1;
        trans = constrain(alpha, 101, 200);
      } else if (val <= 20) {
        alpha += 1;
        trans = constrain(alpha, 0, 100);
      }
    
      if (val <= 20) {
        alpha += 1;
        trans = constrain(alpha, 0, 100);
      }
    
      println(trans);
      noTint();
      image(light, 0, 0, width, height);
    
      tint(255, trans); 
      image(water, 0, 0, width, height);
    }
    
    void movieEvent(Movie m) {
      m.read();
    }
    
  • in processing I get a loop of specific numbers that do not correspond to the sensor

    can we have a clue?

Sign In or Register to comment.