Loading...
Logo
Processing Forum
I draw three curves with serial data.And now ,I wanna  mark a circle on the peak in every period on the three curves?
the following is my curves and the circle on the line ? but it is not my favorite?


Replies(2)

What is the current state of your code?
You probably need to memorize a number of values, and see when there is an inflection in the values.
But then, you will have many small peaks, do you need to mark them all or only the stepper ones?
THX for your answer!
I need to mark on the peaks!

for time saving, here only is the code that draw the line and ellipse.
  noFill();
  beginShape();                                  // using beginShape() renders fast
  for ( x = 1; x < RawX.length-1;x++) {
    stroke(255,0,0);     
    vertex(x, ScaledX[x]+100);

    if(A==1)
    {
         
    }
  }
 endShape();
  
    beginShape();                                  // using beginShape() renders fast
 for ( x = 1; x < RawY.length-1;x++) {
     stroke(0,255,0);     
    vertex(x, ScaledY[x]+200);

    if(B==1)
    {
         
    }
  }
  endShape();

    beginShape();                                  // using beginShape() renders fast
  for ( x = 1; x < RawZ.length-1;x++) {

    
    stroke(0,0,255);    
    vertex(x, ScaledZ[x]);



  }
  endShape();

    if((A==1)){
  for ( x = 1; x < RawX.length-1;x=x+10)
  {
    
    ellipse(x,ScaledX[x]+100,4,4);
    
  }
    
  }
      if((B==1)){
  for ( x = 1; x < RawY.length-1;x=x+10)
  {
    
    ellipse(x,ScaledY[x]+200,4,4);
    
  }
    
  }
  
    if((C==1)){
  for ( x = 1; x < RawZ.length-1;x=x+10)
  {
    
    ellipse(x,ScaledZ[x],4,4);
    
  }
    
  }



and here is the serial event code.

void serialEvent(Serial port){ 
   String inData = port.readStringUntil('\n');
   inData = trim(inData);                 // cut off white space (carriage return)
   
   if (inData.charAt(0) == 'X'){          // leading 'S' for sensor data
     inData = inData.substring(1);        // cut off the leading 'S'
     Sensor_X = float(inData)*100;                // convert the string to usable int
    // Sensor=Sensor_X;
     //println(Sensor);
   }
      
   if (inData.charAt(0) == 'Y'){          // leading 'S' for sensor data
     inData = inData.substring(1);        // cut off the leading 'S'
     Sensor_Y = float(inData)*100;                // convert the string to usable int
     //println(Sensor_Y);
   }
      
   if (inData.charAt(0) == 'Z'){          // leading 'S' for sensor data
     inData = inData.substring(1);        // cut off the leading 'S'
     Sensor_Z = float(inData)*100;                // convert the string to usable int
     //println(Sensor_Z);
   }
//   if (inData.charAt(0) == 'Q'){          // leading 'S' for sensor data
//     inData = inData.substring(1);        // cut off the leading 'S'
//     Sensor_X_angle = float(inData)*100;        // convert the string to usable int
//     
//     //println(Sensor_X_angle);
//   }
//      
//   if (inData.charAt(0) == 'T'){          // leading 'S' for sensor data
//     inData = inData.substring(1);        // cut off the leading 'S'
//     Sensor_Y_angle = float(inData)*100;        // convert the string to usable int
//     //println(Sensor_Y_angle);
//   }
//      
//   if (inData.charAt(0) == 'K'){          // leading 'S' for sensor data
//     inData = inData.substring(1);        // cut off the leading 'S'
//     Sensor_Z_angle = float(inData)*100;        // convert the string to usable int
//     //println(Sensor_Z_angle);
//   }
     if (inData.charAt(0) == 'S'){          // leading 'S' for sensor data
     inData = inData.substring(1);        // cut off the leading 'S'
     S = inData;        // convert the string to usable int
     //println(S);
   }
        if (inData.charAt(0) == 'A')
        {          // leading 'S' for sensor data
        A=1;
        B=0;
        C=0;
        println('A');
        }
        //else
        //A=0;
        
        if (inData.charAt(0) == 'B')
        {          // leading 'S' for sensor data
        B=1;
        A=0;
        C=0;
        println('B');
        }
        //else
        //B=0;
        if (inData.charAt(0) == 'C')
        {          // leading 'S' for sensor data
        C=1;
        A=0;
        B=0;
        println('C');
        }
        if(inData.charAt(0) == 'D')
        {
          D++;
          
//          if(D>=200)
//          {
          A=0;
          B=0;
          C=0;
          D=0;
          //}
        }
        //else
        //C=0;
   

}