outofmemoryError
in
Programming Questions
•
1 year ago
Hey guys
I'm totally new to processing and I'm learning as I go.. but there is something I couldn't figure out..
I've made a sketch that connects to arduino with a firmata. All it does, is wait for a button to be pushed, and then start a sequence of playing a short sound, switch on lights (kind of an LED flash), then play another short sound and take a picture using cam.read.. it works.. for a while
this is my sketch:
import processing.video.*;
import processing.serial.*;
import cc.arduino.*;
import ddf.minim.*;
Minim minim;
AudioPlayer song1; //short .wav file
AudioPlayer song2; //short mp3 file
Arduino arduino;
int ledPin1 = 4; // led connected to pin 4
int ledPin2 = 5; // led connected to pin 5
int ledPin3 = 6; // led connected to pin 6
int butPin = 2; // microswitch connected to pin 2
int x = 1; // serial number of the pictures saved
int val; // get's the value of the switch
Capture cam;
void setup()
{
//println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[1], 57600);
arduino.pinMode(ledPin1, Arduino.OUTPUT);
arduino.pinMode(ledPin2, Arduino.OUTPUT);
arduino.pinMode(ledPin3,Arduino.OUTPUT);
arduino.pinMode(butPin,Arduino.INPUT);
size(640, 480);
cam = new Capture(this, 640, 480);
PImage timeIMG;
minim = new Minim(this);
}
void draw()
{
val = arduino.digitalRead(butPin);
println(val);
song1 = minim.loadFile("scream.wav");
song2 = minim.loadFile("medical006.mp3");
if (val == 0){
song2.play();
delay(3000);
arduino.digitalWrite(ledPin1, Arduino.LOW); // the relays work on LOW
arduino.digitalWrite(ledPin2, Arduino.LOW); // creating a flash effect by switching the led on and off
arduino.digitalWrite(ledPin3, Arduino.LOW);
song1.play();
arduino.digitalWrite(ledPin1, Arduino.HIGH);
arduino.digitalWrite(ledPin2, Arduino.HIGH);
arduino.digitalWrite(ledPin3, Arduino.HIGH);
arduino.digitalWrite(ledPin1, Arduino.LOW);
arduino.digitalWrite(ledPin2, Arduino.LOW);
arduino.digitalWrite(ledPin3, Arduino.LOW);
delay(800);
if (cam.available() == true) {
cam.read();
image(cam, 0 ,0);
save("image_" + x + ".jpg");
x++;
arduino.digitalWrite(ledPin1, Arduino.HIGH);
arduino.digitalWrite(ledPin2, Arduino.HIGH);
arduino.digitalWrite(ledPin3, Arduino.HIGH);
delay(1000);
}
}
arduino.digitalWrite(ledPin1, Arduino.HIGH);
arduino.digitalWrite(ledPin2, Arduino.HIGH);
arduino.digitalWrite(ledPin3, Arduino.HIGH);
}
void stop()
{
song1.close();
song2.close();
minim.stop();
super.stop();
}
I know it's written bad, but I gathered it from a bunch of examples.. anyway, after working a few rounds of pressing the button making the sounds and taking the picture, it says: "
outofmemoryError may need..."
I've tried to increase the memory to the max possible but the problem doesn't go away.
For the record it only started happening after I've added the "song2" which is very a 3sec short mp3 file.
If that is the reason, what kind of file should I use, and if not then what is the problem?
Lastly, if you have any other suggestions on how to make this sketch better I would love to hear that as-well.
thanks
1