I am making a work using serial communication between Arduino and processing.
The switch ON/OFF data obtained from the two tact switches connected to Arduino is sent to Processing. I want to use the two tact switches for stopping and restarting.
Processing reads 20 images and displays them.
What I want to do is to stop/resume the loading of the image on the Processing side according to the value of the switch sent from Arduino.
In the following code, when the stop switch is pressed, sensors = 1 is sent, and reading of the image is stopped by noLoop () in the if statement. However, it cannot be resumed with the value sensors = 2 sent when the other resume switch is pressed.
It can be resumed by clicking the mouse with loop () in mousePressed (), but this time I want to resume using the value from Arduino.
Please give me an answer.
import processing.serial. *;
Serial myPort;
int numFrames = 20;
int sensors;// Store the sensor value
PImage [] images = new PImage [numFrames];
void setup () {
background (255);
size (1280, 800);
frameRate (40);
imageMode (CENTER);
for (int i = 0;i<images.length;i ++) {
images [i] = loadImage ("animation-" + nf (i, 3) + ". png");
images [i] .resize (1280, 800);
}
myPort = new Serial (this, "/dev/cu.usbmodem143401", 9600);
}
void draw () {
int frame = frameCount% numFrames;
if (sensors == 0) {
image (images [frame], width/2, height/2);
}
if (sensors == 1) {
// image (images [frame], width/2, height/2);
noLoop ();
}
if (sensors == 2) {
loop ();
}
}
void serialEvent (Serial p) {
sensors = p.read ();
println (sensors);
}
void mousePressed () {
loop ();
}
-
Answer # 1
-
Answer # 2
This is a completely different method, but it has led to self-solving.
It is a method to export 20 images in advance as one video, read it, and stop/resume with pause () and play ().
However, it seems heavy to load videos one by one, so I think TN8001's answer is the best way.import processing.serial. *; Serial myPort; import processing.video. *; Movie myMovie; int sensors = 0; void setup () { size (1920, 800); background (0); frameRate (60); myMovie = new Movie (this, "myMovie.mov"); myMovie.loop (); myPort = new Serial (this, "/dev/cu.usbmodem143401", 9600); } void draw () { background (255); if (sensors == 0) { image (myMovie, width/2, height/2); } if (sensors == 1) { myMovie.pause (); } if (sensors == 2) { myMovie.play (); } } void movieEvent (Movie m) { m.read (); } void serialEvent (Serial p) { sensors = p.read (); println (sensors); }
Related articles
- javascript json i want to loop and pass values
- c++ - arduino: i want to turn it on and off with a tact switch
- On the for loop and foreach loop in C #
- Follow me for JavaScript for loop and for in loop
- C # for loop and while loop execution
- Summary of java list loop and map loop
- security - should i stop bcrypt and hash with sha?
- loop i and j with python: for syntax
- arduino - restart wio lte
- amazon ec2 - restart from ec2 stop
- arduino - how to use canwake () and cansleep ()
- how to stop php output and display only html
- php - loop and register db
- xcode - play and stop swift mp3
- save sensor values in csv format using arduino and processing
- to discharge csv from arduino with processing
- cooperation between processing and arduino
- java - i want to write a program in which an object like the game "taiko no guru" flows and sounds when it overlaps
- java - a program that reads the value of the optical sensor, generates a random number only once, and displays the character acc
- pass information from espr developper (arduino environment) to processing via serial communication
- java - a program that sounds in arduino when the cursor touches a shape in processing, and stops when the cursor stops touching
- java - the program that reads the value of the ultrasonic sensor using arduino and displays the numerical value with processing
- java - cooperation between arduino and processing serial communication
- java - controlling two arduino servos and one speaker from processing causes the servo movement to become unstable
I don't have an Arduino, so it looks like
Is this okay? I'm sorry if I removed it.