hello!
im have almost no programming experience and would be greatful for help :-) i wrote a small program toggling a slideshow & sounds (mp3) with arduino buttons, but it doesn't run stable.
when i press the buttons on arduino quickly, processing crashes with an error window. i wouldn't mind, but others are going to use it in a situation where chances are high they will hit the buttons quickly! it crashes, saying:
Java(TM) SE Platform binary doesn't work any more
i figued, if i cut out the part of code dealing with sound, i can hit the arduino buttons in a frenzy without problems.
a second matter is, if i try to export the sketch and run it as an *.exe (i close processing entirely to free the serial port) it just loads some blank screen, nothing happens. i have no i idea what to look for in this second matte. i am still guessing it doesn't start because there's a communication issue between arduino and the program once it's an *.exe?
import processing.serial.*;
import processing.sound.*;
import cc.arduino.*;
PFont f;
Arduino arduino;
SoundFile nowplaying;
int y; // int für screensaver line
int counter = 1; // int welche bild/textdatei eingelesen wird
int coinPin = 2; //anschluss münzprüfer
int enterPin = 4; // anschluss button
int relayPin = 8; // anschluss button
int servoPin = 10; // anschluss servo
int coinState = 0; // münze ja/nein
int enterState = 0; // button ja/nein
int counterMax = 10;
color colA = color(237, 51, 57);
color colR = color(random(256), random(256), random(256));
void setup () {
printArray(PFont.list()); //create a font
f = createFont("Oxygen-Bold.ttf", 64);
textFont(f);
textAlign(CENTER, CENTER);
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino.pinMode(coinPin, Arduino.INPUT);
arduino.pinMode(enterPin, Arduino.INPUT);
arduino.pinMode(relayPin, Arduino.OUTPUT);
arduino.pinMode(servoPin, Arduino.SERVO);
arduino.digitalWrite(relayPin, 0);
arduino.servoWrite(servoPin, 180);
size(600, 600); // window size
background(loadImage(counter + ".jpg"));
nowplaying = new SoundFile(this, (counter + ".mp3"));
}
void draw() {
if (arduino.digitalRead(coinPin) == 1) {
counter = 1;
background(loadImage(counter + ".jpg"));
coinState = 1;
}
if (coinState == 1 && enterState != arduino.digitalRead(enterPin)) {
enterState = arduino.digitalRead(enterPin);
if (enterState == 1) {
counter = counter + 1;
if (counter <= counterMax) {
background(loadImage(counter + ".jpg"));
nowplaying.stop();
nowplaying = new SoundFile(this, (counter + ".mp3"));
nowplaying.play();
} else {
nowplaying.stop();
counter = 0;
coinState = 0;
arduino.servoWrite(servoPin, 0);
delay(1000);
arduino.servoWrite(servoPin, 180);
}
}
}
if (coinState==0) {
background(255);
fill(colA);
text("ENTER COIN", 300, 300);
stroke(colA); // screensaver line
line(0, y, width, y);
y++;
if (y > height) {
y = 0;
}
}
}