We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm using an arduino uploaded with firmata. I have a potentiometer hooked up and as the user turns the potentiometer, depending on the value they land on, a certain video will play. So if they turn it up more a different video will play etc. What's happening is I have to turn the potentiometer to a value, and then turn it all the way back to zero and then the corresponding video from the first value will play. In between it's showing the "image" I'm calling as a part of the video, but usually only one of them, not all of them. I'm new to the video library and processing & arduino in general. Thanks for your help!
import processing.serial.*;
import cc.arduino.*;
import org.firmata.*;
import processing.video.*;
Arduino arduino;
Movie oneDegree, twoDegrees, threeDegrees;
int sensorPin = 0; // select the input pin for the potentiometer
int val;
void setup() {
size(960, 540);
arduino = new Arduino(this, Arduino.list()[3], 57600); //sets up arduino
val = arduino.analogRead(sensorPin);
println(Arduino.list());
oneDegree = new Movie(this, "comp1.mp4");
twoDegrees = new Movie(this, "comp2.mp4");
threeDegrees = new Movie(this, "comp3.mp4");
}
void draw() {
val = arduino.analogRead(sensorPin);
println(val);
image(oneDegree, 0, 0);
image(twoDegrees, 0, 0);
image(threeDegrees, 0, 0);
if(val > 10 && val < 348) {
oneDegree = new Movie(this, "comp1.mp4");
oneDegree.play();
}
else if(val > 348 && val < 686) {
twoDegrees = new Movie(this, "comp2.mp4");
twoDegrees.play();
}
else if(val > 686 && val < 1024) {
threeDegrees = new Movie(this, "comp3.mp4");
threeDegrees.play();
}
if (oneDegree.time() == oneDegree.duration()) { //movie must be finished
twoDegrees.play();
}
if (twoDegrees.time() == twoDegrees.duration()) { //movie must be finished
threeDegrees.play();
}
}
void movieEvent(Movie m) {
m.read();
/* if (m == oneDegree) {
oneDegree.read();
}
else if (m == twoDegrees) {
twoDegrees.read();
}
else if (m == threeDegrees) {
threeDegrees.read();
}*/
}
/* void movieEvent(Movie ) {
if (val <= 348) {
oneDegree.read();
}
else if (val > 348 && val <= 686) {
twoDegrees.read();
}
else if (val > 686 && val <= 1024) {
threeDegrees.read();
}
} */
Answers
This next is untested code.
Kf