I wrote a simple code , using Arduino switches to move a simple image on Processing left and right.
It works when I run the code from Processing window. But when exporting to OSX app, it stops working! I try to debug and isolate the problem a bit: i think it is the serial communication. any solution??
Processing code:
//this code reads from serial port and move Mario around
//based on the switch pressed on Arduino board
// import the serial library
import processing.serial.*;
import gifAnimation.*;
// create an instance of the serial library
Serial myPort;
// create an instance of PImage
//PImage[] animation;
Gif loopingGif;
Gif loopingGif2;
int keypress =0;
void setup() {
size (500, 500);
frameRate(100);
loopingGif = new Gif(this, "mario3.gif");
loopingGif.loop();
loopingGif2 = new Gif(this, "mario14.gif");
loopingGif2.loop();
println("Available serial ports:");
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
}
int x=0;
int y=50;
void draw() {
if ( myPort.available() > 0) {
keypress = myPort.read();
// print the value to the status window
println(keypress);
}
background(255);
image(loopingGif, x, y, loopingGif.width* 2, loopingGif.height*2);
if (keypress == 1) {
x ++ ;
image(loopingGif, x, y, loopingGif.width* 2, loopingGif.height*2);
}else if (keypress == 2){
x --;
image(loopingGif, x, y, loopingGif.width* 2, loopingGif.height*2);
I am trying to make a very simple program using a potentiometer to adjust the background colour of Processing output window.
I write the potentiometer value into the serial port, and the processing code reads the information from the serial port. The problem I am facing is there is a ridiculously long delay of Processing reading the information from serial port!
I am using a mac.
Does anyone have this problem? Is there a solution?
[edit: when I said ridiculous, i did mean sometimes up to 1 minutes!!]