processing video and ultrasonic sensor

Hey there,

first of all, I'm not sure if I'm in the right part of the forum with this. If not, please put me in the right part. So, now to my problem.
I'm trying to control a video through an ultrasonic sensor on my arduino board. I already got the code for the arduino to get the sensor data in cm.

long laenge;
long cm;

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

void loop() {
 pinMode(8, OUTPUT);
 pinMode(9, INPUT);
 
 digitalWrite (8,LOW);
 delayMicroseconds(2);
 digitalWrite (8,HIGH);
 delayMicroseconds(5);
 digitalWrite(8,LOW);
 
 laenge = pulseIn(9,HIGH);
 
 cm = (laenge*34)/2000;
 
 Serial.print(cm);
 
 delay(350);
}

Where I'm having trouble with is writing a processing code which is playing a video when the range is at 3 cm and showing nothing when the range is above that. The video should always replay when the range was above and i getting below again.

Maybe someone can help me with this problem.

Thanks in advance!

I got it to go on my own. The video is now playing when I'm close to the sensor and it pauses when I'm not.
The only problem I have now, is that the video should not at all be shown when I'm not close to the sensor. There should be nothing on the screen till something comes close to the sensor and then the video should start playing.
Here's my code so for:

//Arduino//

#define trigPin 8
#define echoPin 9

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {
  long distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2); 
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); 
  digitalWrite(trigPin, LOW);
  distance = pulseIn(echoPin, HIGH);

  if (distance <= 200){
    Serial.print("1");
  }
  else {
    Serial.print("0");
  }
  delay(500);
}

//Processing//

import processing.serial.*;
import processing.video.*;
Movie myMovie;
import processing.serial.*;
Serial myPort; // The serial port:
String instring  = "";



void setup() {
  myPort = new Serial(this, "/dev/cu.usbmodemfd121", 9600);
  myPort.bufferUntil('\n');
  size(500, 500);
  frameRate(30);
  myMovie = new Movie(this, "israel.mpeg");
  myMovie.loop();
  myMovie.stop();  
}


void draw() {
  
  if (myMovie.available()) {
    myMovie.read();
  }
  image(myMovie, 0, 0);
  while (myPort.available () > 0) {
   instring = myPort.readString();
   println(instring);
   int sensorAct = Integer.parseInt(instring, 10);
     if (sensorAct == 1){
       println("TEST");
       myMovie.play();
      }
      else {
      myMovie.pause();};
      }
}

Would be great if somebody could help me out here because I'm absolutely lost now.

Hello,

Well i do not have an answer, but was looking exactly for what you have, a video that play when you near and pause when not..... I tried your code as it is but it gives me errors,
Did you manage it with a special trick ?

Semi:
There should be nothing on the screen till something comes close to the sensor and then the video should start playing.

      myMovie.pause();};

Well, processing does exactly what you tell it to do... it pauses the video. If that's not what you want, don't use

pause();

lg, couka