Communication with Arduino
Using Serial communication between Arduino and Processing did not work out because it was to slow. When the baud rate was increased Processing was not able to read the sent data.
Using Firmata - following the tutorial will allow an introduction to basic communication through processing, ensure to upload the relevant sketch from the Arduino IDE before.
Processing code using firmata:
*Please note that this is not working code, those are examples of which parts of the code were added to work with firmata
import processing.serial.*;
import cc.arduino.*;
Serial myPort; // Create object from Serial class
String value; // Data received from the serial port
arduino = new Arduino(this, Arduino.list()[0], 57600);
heartrate1 = arduino.analogRead(0);
heartrate2 = arduino.analogRead(1);
heartrate3 = arduino.analogRead(2);
heartrate4 = arduino.analogRead(3);
if (450 >= heartrate1 || heartrate1 >= 650){
if (450 >= lastheartrate1 || lastheartrate1 >= 650){
startImage1 = photoRow1[int(random(photoRow1.length))];
println("heartrate1 is "+heartrate1);
}
} else {
println("heartrate1 is "+heartrate1);
}
if (450 >= heartrate2 || heartrate2 >= 650){
if (450 >= lastheartrate2 || lastheartrate2 >= 650){
startImage2 = photoRow2[int(random(photoRow2.length))];
println("heartrate2 is "+heartrate2);
}
} else {
println("heartrate2 is "+heartrate2);
}
if (450 >= heartrate3 || heartrate3 >= 650){
if (450 >= lastheartrate3 || lastheartrate3 >= 650){
startImage3 = photoRow3[int(random(photoRow3.length))];
println("heartrate3 is "+heartrate3);
}
} else {
println("heartrate3 is "+heartrate3);
}
if (450 >= heartrate4 || heartrate4 >= 650){
if (450 >= lastheartrate4 || lastheartrate4 >= 650){
startImage4 = photoRow4[int(random(photoRow4.length))];
println("heartrate4 is "+heartrate4);
}
} else {
println("heartrate4 is "+heartrate4);
}
lastheartrate1 = heartrate1;
lastheartrate2 = heartrate2;
lastheartrate3 = heartrate3;
lastheartrate4 = heartrate4;