Sunday, December 4, 2011

And Almost There

I got Arduino speaking with the sensors and then Processing picking up the variable from the USB. Having major issues with Processing trying to get the video to play and respond.
This is what I have so far: it sort of trying to play the video, but nothing presentable. Slightly concerned...but still working and working and working.

import processing.serial.*;
import processing.video.*;
int val = 0;
int port1;

Movie myMovie;
Serial port;

float speed = 1.0;  //make this a variable

void setup() {
  size(320, 240);

  println(Serial.list());
  port = new Serial(this, Serial.list()[0], 115200);
  myMovie = new Movie(this, "Process_Open.m4v");
  myMovie.speed(speed);   //you made speed a string
  myMovie.loop();
 
}


void draw() {      //just trying deleting out stuff
  //  if(myMovie.available()) {
  //    myMovie.read();
  //    image(myMovie,0,0);
  //  }

  while (port.available() > 0) {
    serialEvent();
 //   movieSpeed();
  }
  //background(255,0,46);
 
  }


void serialEvent() {
  println(port.readStringUntil('\n'));
  String portstring = port.readStringUntil('\n');
  println("portstring is   ");
  //port1= Integer.parseInt(portstring);
  //port1= int(port.readStringUntil('\n'));
 
  movieSpeed(port1);
}

void movieSpeed(int port) {

  if (port <= 18) {
    speed *= 4.0;
  }
  else if (port <= 36) {
    speed *= 2.0;
  }
  else if (port <= 54) {
    speed *= 1.5;
  }
  else if (port <= 100) {
    speed *= 1.0;
  }
  else if (port <= 100) {
    speed *= -1.0;
  }
  else {
  //  val = 0;
  }

  playMovie(speed);
}

void playMovie(float speedvalpass) {
//  myMovie.speed(speed);       //we'll uncomment this out if the below doesn't work
 
  if(myMovie.available()) {
    myMovie.read();
    myMovie.speed(speedvalpass);
    image(myMovie,0,0);
  }
}

XBee: http://www.faludi.com/itp_coursework/meshnetworking/XBee/XBee_program_Arduino_wireless.html
http://www.ladyada.net/make/xbee/arduino.html

No comments:

Post a Comment