Hej, I'm new in this whole programming thing but my vision of digital soundshoes keeps me hanging on, eventhough right now I'm having a hard time...
Well here is a question, if anyone has an idea I will change from this
to this
I'm using four pressure sensors to get analog input from arduino to processing. I want to store those in an array to have the input of each sensor seperately to control the frequency of four soundfiles (one for each sensor). With this code (which i luckily enough found somewhere around here, and now added an array) it gives me not the right position of each value. If I push sensor "a" for example the outcoming value changes on two or three positions of the array.
....strange.....
here is the code
import processing.serial.*;
Serial myport;
int val0 = 0; //variable fo units, tens etc.
int val1 = 0;
int val2 = 0;
int val3 = 0;
char val4; //letter tag
int val5 = 0; //variable for 10 and 13 ASCII
int val6 = 0;
int vala; //variable for each sensor
int valb;
int valc;
int vald;
int [] Sensorliste = new int[4];
void setup() {
size(400,400);
frameRate(200);
myport = new Serial(this, Serial.list()[1], 9600);
}
void draw() {
background(0);
if (0 < myport.available()) { // If data is available,
val5 = myport.read(); // read it and store it in val5
if (val5 ==13){ //new line
val6 = myport.read(); //carriage return
val4 = myport.readChar(); //letter tag
//println(val4); //for test purpose
val0 = myport.read() - 48; //48 is ASCII value of 0
//println(val0); //thousands
val1 = myport.read() - 48;
//println(val1); //hundreds
val2 = myport.read() - 48;
//println(val2); //tens
val3 = myport.read() - 48;
//println(val3); //units
int valT = (val0 * 1000) + (val1 * 100) + (val2 * 10) + val3;
switch (val4){
case 'a':
vala = valT;
case 'b':
valb = valT;
case 'c':
valc = valT;
case 'd':
vald = valT;
}
int [] Sensorliste={vala, valb, valc, vald};
Sensorliste[0]=vala;
Sensorliste[1]=valb;
Sensorliste[2]=valc;
Sensorliste[3]=valc;
println(Sensorliste);
}
}
}