We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Array for analog data
Page Index Toggle Pages: 1
Array for analog data (Read 457 times)
Array for analog data
Jul 5th, 2009, 9:13am
 
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  Shocked to this Cheesy

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);
   
  }
 
 
}
}


Re: Array for analog data
Reply #1 - Jul 5th, 2009, 9:33am
 
well I don't know it this solves your problem, but you certainly have got to put some breaks in your switch statement

Code:

switch (val4){
   case 'a':
     vala = valT; break;
   case 'b':
     valb = valT; break;
   case 'c':
     valc = valT; break;
   case 'd':
     vald = valT; break;
   default:
     // good practice to handle other values too
  }


Re: Array for analog data
Reply #2 - Jul 5th, 2009, 10:32am
 
Cheesy Cheesy Cheesy

thanks!
Page Index Toggle Pages: 1