Used the force sensor to pause or unpause a video that is being played.
Processing code
import processing.video.*;
import processing.serial.*;
Movie movie;
Serial port;
String buf="";
String portname = "COM3";
int cr = 13;
int lf = 10;
int waarde;
void setup() {
size(320,240, P2D);
movie = new Movie(this, "cat.mov");
movie.loop();
port = new Serial(this, portname, 9600);
}
void movieEvent(Movie movie) {
movie.read();
}
void draw() {
image(movie,0,0);
}
void serialEvent(Serial p) {
int c = port.read();
if (c != lf && c != cr) {
buf += char(c);
}
if (c == lf) {
waarde = int(buf);
if (waarde > 0)
movie.pause();
else
movie.play();
println("val="+waarde);
buf = "";
}
}
Arduino Code
int sensorPin = 0; // select the input pin for the sensor
int val = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(sensorPin); // read the value from the sensor, 0-1023
Serial.println(val); // writing the value to the PC via serial connection
delay(1000); // rest a little...
}