We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm currently in the middle of creating a book on which the content is projected down rather than printed on to the pages. This is because I want to incorporate media like video and animation in to the project.
I'm using an ultrasonic sensor to tell the Arduino if a page is turning or not. It sends out a signal which is displayed in the Serial Monitor as either PageTurn or NoPageTurn respectively. This is the Arduino code:
#define trigPin 12
#define echoPin 13
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance >= 400 || distance <= 2){
Serial.println("Out of range");
}
else if (distance >=3 && distance <=100){
Serial.print(distance);
Serial.println(" cm");
Serial.println("PageTurn");
}
else {
Serial.print(distance);
Serial.println(" cm");
Serial.println("NoPageTurn");
}
delay(2000);
}
The Arduino code is working perfectly. The serial port displays either PageTurn or NoPageTurn depending on whether not the page of the physical book is turned.
I want to bring this in to Processing but I am limited in knowledge on the subject. My aim is to use Processing to display video, but I can't get the video to display properly. This is my Processing code: import processing.video.*; Movie myMovie;
void setup() {
size(200, 200);
myMovie = new Movie(this, "ch1.mov");
myMovie.play();
}
void draw() {
image(myMovie, 0, 0);
}
void movieEvent(Movie m) {
m.read();
}
Questions
How do I make the video display through Processing?
How can I use the sensor to change the video that's playing, when it displays "PageTurn" in the serial port in Arduino. The pages of the book are all .mov files, labelled ch1.mov - ch6.mov. When the page is turned, I want to change the video that's projected on to the page. This is done through Processing I assume, but I can't figure out how.
Also, I'm going to need to display the video in full screen mode, in order for it to be projected properly. I'm considering using the GSVideo Library for this, but I don't know how to go about this.
I come from a design background so all of this is new to me, if I should be using something other than Processing to do the video stuff please let me know.
Thanks for any help you can provide on the subject.
Answers
I'm actually just sniffing around the internet looking for ways to control video with Arduino input and stumbled upon your post. I'm by no means an expert as I've just begun experimenting with the combination Arduino - Processing. (My first goal is to control the speed and frame position of videos - so far I've got code working that makes a turning knob, potentiometer, controlling the playback speed). What I've learned so far might be helpful in your case so bear with me as I might be talking a little chaotic/blurry/ ...:
Question1: To make video play in Processing: the code above looks about right, just place your videofile(s) inside a folder called 'data' next to your *.pde (or you could even use an internet address, e.g. "http://nojpeg.org/img/NoJPEG.jpg") Also make sure that Processing is listening to the Arduino by selecting the right serial port. You can use this code to list available ports, and afterwards changing the number between the brackets to the right port (start counting at zero, so if your port is listed as the fourth change the number between the brackets to 3: [3]) So run the code once, change the port to the right number.
Question 2: In your Arduino code use Serial.write instead of Serial.print e.g. my code for a potentiometer looks like this:
What I've found was that the delay might be too fast for Processing, the solution I found somewhere was to put this into the processing code:
myPort.clear();
Question 3: I haven't tried this before, but maybe just put your image size to the resolution of your screen. a quick lookup learns me that this code can be used, not tested yet though:
size(displayWidth, displayHeight);
Question 4: On my not so very fast laptop I found my experiment rather laggy, hence why I'm looking at other projects and tips. So no idea whether Processing is the right tool.
For reference here's my full Processing code:
hello,
I am trying to find out the same process, did it work with you guys?