Friday, November 4, 2011

Midterm02


import processing.serial.*;
import cc.arduino.*;
import processing.video.*;
int sensorUsed = 0; //Set
this to whatever input sensor io pin you're using
PImage cat;
Movie myMovie;
//color myMovieColors[];
Arduino arduino;
int switcher = 0;
void setup() {
size(641, 481, P2D);
arduino = new Arduino(this,
Arduino.list()[0], 57600);
myMovie = new Movie(this,
"../Bwire.mov");
myMovie.loop();
image(myMovie, 0, 0);
}
void movieEvent(Movie m) {
m.read();

}
void draw() {
image(myMovie, 0, 0);
fill(0, 0, 255);
//if the sensor switch
float sensorValue =
arduino.analogRead(sensorUsed);
float sensorValueMapped =
map (sensorValue, 0, 1024, 150, width);
tint(255);
if(sensorValueMapped
> 400){
myMovie.loop();
switcher = 1;
}
else if (sensorValueMapped
== 150){
if (switcher == 0)
myMovie.jump(2);
if (switcher == 1)
myMovie.pause();
}

println(sensorValueMapped);
}

No comments:

Post a Comment