We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I am having trouble getting my sketch to respond to my ardunio in actual time. There is about a 30 second delay. The delay gets longer as the sketch continues to run.
My goal: under certain conditions from the Arduino a sprite will play in processing. There are 4 condition (1 0, 1 1, 2 0, 2 1).
Code:
int numFrames = 7; int currentFrame = 0; PImage[] images = new PImage[numFrames];
import processing.serial.*;
Serial myPort;
String val;
void setup() { size(1000,600); frameRate(5);
images[0] = loadImage("images/heart(1).gif"); images[1] = loadImage("images/heart(2).gif"); images[2] = loadImage("images/heart(3).gif"); images[3] = loadImage("images/heart(4).gif"); images[4] = loadImage("images/heart(5).gif"); images[5] = loadImage("images/heart(6).gif"); images[6] = loadImage("images/heart(7).gif");
String portName = Serial.list()[1]; myPort = new Serial(this, portName, 9600);
}
void draw() { background(255);
//Display Serial Data if (myPort.available() > 0) { if ( (val = myPort.readStringUntil(ENTER)) != null ) val = trim(val); else return; if (val != null) { println(val); } }
//control sketch currentFrame = (currentFrame+1) % numFrames; // Use % to cycle through frames int offset = 0;
if ("1 1".equals(val)) {
image(images[(currentFrame+offset) % numFrames], 333, 200);
offset+=2;
}
if("2 1".equals(val)){
image(images[(currentFrame+offset) % numFrames], 666, 200);
offset+=2;
player.play();
}
}
Any help is greatly appreciated!