We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hello,
I am wanting to replace the following code. I have a capacitive touch sensor attached to processing that opens up a random image every time the sensor is held, when the sensor is let go this image disappear.
I want to essentially replace the image files with 26 short video clips at 25 frame rate. Im not sure how to change this code to make that happen.
Any help would be great!
import processing.serial.*;
int threshold = 30;
PImage [] picArray = new PImage [26];
Serial myPort;
boolean holdImage=false;
int imgIndex;
void setup() {
size (500, 500);
for (int i=0; i<picArray.length; i++)
picArray[i]=loadImage(i + ".png");
myPort = new Serial(this, Serial.list()[1], 9600);
myPort.bufferUntil('\n');
}
void draw() {
background (255, 255, 255);
if (holdImage==true) {
image(picArray[imgIndex], 0,0);
}
}
void serialEvent(Serial myPort) {
String inString = myPort.readStringUntil('\n');
if (inString != null) {
inString = trim (inString);
float[] touches = float (split(inString, ","));
if (touches.length >=1) {
int touch1Value = touches[0] >= threshold ? 1: 0;
if (touch1Value == 1) {
if (holdImage == false) {
imgIndex=int(random(picArray.length));
holdImage=true;
}
} else
holdImage=false; //RELEASE holder so to detect next usr press event
}
}
}
Answers
Have you tried simply playing a movie?
Explore previous posts: https://forum.processing.org/two/search?Search=capacitive
Kf
Unfortunately I'm not very skilled at using processing. I wouldn't know how to play a movie.Yet I want this movie to be started as soon as the capacitive sensor is held down, and stop returning to a white screen when It is finished.
Any examples would be great, I'll have 26 video labelled 123..etc
In Processing, install the library called video using the library manager. After that, you can open one of the examples under File >> examples and go to libraries >> video >> movie and run some of the examples there. After you have an example running, then you need to use that example to play a couple of your movies. This is what I would do first anyways...
Kf
I've still not managed to resolve this guys :(
I literary just want the code to play a random array of videos instead of images when the sensor is held
Here is the example of how to play a movie:
Here is the example for using
play()
:One approach is to create an array of movies instead of images. So, instead of:
...create an array of Movies:
Try this
https://forum.processing.org/two/discussion/4333/how-can-i-get-multiple-videos-to-play-one-after-another-and-triggered-by-specific-keys
It is important you play the basic movies first. You need to figure out where to place your movie files, to become familiar with Processing and this is an important step so to be able to use it with your capacitive sensor project.
Kf
I have attempted at the below code.
The code does play a video from the capacitive touch however it doesn't appear to be randomised.
Also when the sensor is released the video pauses instead of disappearing the sound also carries on for some reason.
lines 60, 61 have a hard-coded value in there. is that what you want?
No, I basically want a randomised video to be displayed when the sensor is held.
Once the sensor is released I want the video to stop playing and clear from the screen.
then you need to randomise the index values in lines 60 and 61. if it says "1" then you'll only every see video 1.
I'm kinda new at processing, how would I do this for a video?
https://forum.processing.org/two/discussion/comment/85389/#Comment_85389
Also you use this:
Also remove holdimage in draw as it is not needed. If you want to hold your image, you simply pause all your movies.
Now for the random part:
Kf
After making these alterations it now says - error, disabling serial event()
My code is below.
Line 23, it should be 2, not 3.
Also, I will suggest running a code only for movies. When you know it is running, then you merge it with your serial code. Otherwise is more difficult to debug.
Kf
The video file does not appear to be showing, It also does not recognise when I let go of the sensor
Try this.
Kf
When the sensor is held within this code both movies play at the same time, I just want one movies to play each time the sensor is held until it is let go.
I feel this code is going in the right direction
Ok, so you need to use a variable that lock the state of your movie. It should choose a new movie only after the Arduino input goes below threshold.
Kf
That seems to work :)
However when the sensor is released the randomised movie still plays for some reason?
When the sensor is realised I want it to return to a blank/white screen.
Rewritten....
Kf
Copy lines 20 and 21 inside else block in line 27.
Also modify draw like this:
Kf
With this suggestion the movies appear and disappear when they should in regards to the sensor, however they don't seem to be playing it is only a still image of the first part of the movie.
It is hard when I am not able to reproduce the problem. This is the reason I suggested working with playing only the movies. You could use the mouse event keypressed/keyreleased to simulate when the Arduino is pressed down or not.
Kf
Line 62... You need a extra set of brackets to capture the block of that else. I made a mistake and removed those brackets before. That should solve the problem.
Kf
That has solved the problem,
However I want my movie to reset rather than pause and replay when the sensor is let go and then pressed.
If this is figured out I think I will be done.
I managed to figure this out.
Thank you very much for your help!
My final code is below...
Perfect!
Kf
I've tried to add 26 short 10 second movies to the code, however I can't seem to see the visuals I can only here the music playing.
I just want my movies to be centred on the page so it is viewable, these movies are set at 500pixels - 500pixels.
My code is below.
bump!!
If you run 3 movies for example, you have the same problem?
Other comments:
Don't use 26 in your code. Instead use for example:
final int nMovies=26;
To center the movie, use
imageMode(CENTER);
and replace line 55 withimage(myMovie[index], width/2,height/2);
Also change 79 and 80 with
myMovie[index].pause();
Lastly, change 88 and 89 with
myMovie[index].stop();
Kf