Thursday, September 19, 2019

processing code to display CSV data

//import io.inventit.processing.android.serial.*;

import processing.serial.*;
import static javax.swing.JOptionPane.*;
//import processing.net.*;
//Client ennodaClient;
Serial envazhi;
int nikazhmadhippu1, nikazhmadhippu2, nikazhmadhippu3;
int z=10;
 
int[] akalavu;
int[] meiyalavu;
int[] uyiralavu;
int ullpiri;
int i,d,p;
//int value=20;

void setup()
{
   
   
   
 //  fill(180, 0, 0);
 // for (d=0; d<1080; d++){
 // text ("rajaguru", 600, d); }
  
  //text ("rajaguru", 600, 800);
   
  
  fullScreen();
  //size(1000, 550);
  frameRate(60);
    
  strokeWeight(1);
  smooth(); // or noSmooth();
  akalavu = new int[200];
  meiyalavu = new int[200];
  uyiralavu = new int[200];
  String portName = Serial.list()[1];
  envazhi = new Serial(this, portName, 230400);
 
 // text("STOP",1855,30);
  
  
  
}
 
void draw()
{
  
  fill(0, 0, 180);
  if (d<300)
   {
    background(255);
    //textSize(5+d);
    textSize(20);
    text ("rajaguru", 1920-d, 600); 
    d+=5; 
   } 
  fill(255,255, 255);
  
  
  //text("STOP",1855,20);
  //fill(20);
  line(1850,10, 1900, 50);
  line(1900,10, 1850, 50);
  line(1900,10, 1900, 50);
  line(1900,50, 1850, 50);
  line(1850,10, 1850, 50);
  line(1850,10, 1900, 10);
  
  textSize(12);
  
  
  
  String ull = envazhi.readStringUntil('\n');
 
  if(ull != null)
  {
      
   int[] ullpiri = int(split(ull, ","));
   
   nikazhmadhippu1 = abs(int(ullpiri[0]));
   nikazhmadhippu2 = abs(int(ullpiri[1]));
   nikazhmadhippu3 = abs(int(ullpiri[2]));
   background(255);
   int lowest = min(ullpiri);
   int highest = max(ullpiri);
   p++;
   println( p);
   
     
   {
   
     for(int i = 1; i < 200; i++) 
        {
         
          akalavu[i-1] = akalavu[i]; //shifting every value to previous array-element ANDDDDDDDDD storing 200 subsequent values in  200 array-elements
          meiyalavu[i-1] = meiyalavu[i];
          uyiralavu[i-1] = uyiralavu[i];
        }
        
               
       // print(lowest);
       // print(",");
       // println(highest);
      //  println();
        
   akalavu[200-1] = int (map(nikazhmadhippu1, lowest, highest, 20, 500)) ;
   meiyalavu[200-1] = int( map(nikazhmadhippu2, lowest, highest, 400, 1000));
   uyiralavu[200-1] = int( map(nikazhmadhippu3, lowest, highest, 20, 600));
 
  }
  
    {      
     beginShape();
      strokeWeight(2);
      stroke(0, 0, 250); //(rgb) colored lines, blue for z-axis
      {
       int j=1;
       int i=1;
      // int d=0;
      //plotting allllllllllllllllll 100 array-elements in x-y graph here.        
      // variable-i gives 100 numbers of array-elements which are plotted on the y-axis; variable-j gives the x-axis position.
      // variable z helps to increase or decrease the x-axis-gap between 2 successive inputs. 
       for (i=1, j=1; i<199 && j <(z*200); i++, j= j+z) 
        {    
           
  //if (d<10800){
 // for (d=0; d<10800; d+=10){
 // text ("rajaguru", 600, d/10); }}
          
           if (akalavu[i-1]>0){
         curveVertex(j, akalavu[i-1]); //as the loop runs, on every loop a single vertex-point is fixed in the display-window-matrix and....on next loop another vertex-point is fixed. and those 2 points get linked by a curve. 
                  
           }
           
        }                             //this logic of curve-fitting between 2 successive points continues till the end of THIS "for" loop, resulting in the curve-plot.
      
      }
     endShape();     
    } 
 
    //x-axis
    
      {      
      beginShape();
      strokeWeight(2);
      stroke(0, 250, 0); //green for x-axis
       {
       int j=1;
       int i=1;
      
       for (i=1, j=1; i<199 && j <(z*200); i++, j= j+z) 
        {            
          if (uyiralavu[i-1]>0){
          curveVertex(j, uyiralavu[i-1]); //as the loop runs, on every loop a single vertex-point is fixed in the display-window-matrix and....on next loop another vertex-point is fixed. and those 2 points get linked by a curve. 
          
          
         }
        }                             
    
       }
      endShape();     
      }
    
    //y-axis  
    
      {      
      beginShape();
      strokeWeight(2);
      stroke(250, 0, 0); //red for y-axis
       {
       int j=1;
       int i=1;
     
       for (i=1, j=1; i<199 && j <(z*200); i++, j= j+z) 
        {                                              
         if (meiyalavu[i-1]>0){
         curveVertex(j, meiyalavu[i-1]);
         }
        }                             
       
       }
      endShape();     
      }
   
  }
  
 nEram();
  framerate();
 //name();

}

//void name() {
 // PImage padam1, padam2, padam3, padam4, padam5, padam6, padam7;
  //fill(80, 80, 200);
 // text ("rajaguru", 1550, 100);
  //fill(255, 255, 255);
  //padam2 = loadImage("enperu.png");
  //image(padam2, 1000, 0, 129, 29);
 // padam1 = loadImage("tamilsource.png");
 // image(padam1, 10, 5, 50, 50);
  //padam3 = loadImage ("rate.png");
 // image(padam3, 215, 15, 325, 28);
  //padam4 = loadImage ("count.png");
  //image(padam4, 248, 43, 292, 25);
  //padam5 = loadImage ("duration.png");
  //image(padam5, 200, 68, 340, 28);
  //padam6 = loadImage ("time.png");
  //image(padam6, 333, 93, 207, 26);
  //padam7 = loadImage ("axes.png");
  //image(padam7, 70, 5, 108, 115);
  
  //image(padam2, 0, 230, 100, 20);
//}

void nEram(){
  textSize(15);
  fill(180, 0, 0);
 // int maNi = hour();
 // int nimidam = minute();
 // int nodi = second();
 
  //text (maNi, 550,110);
  //text (": "+ nimidam, 570, 110);
  //text ( " : " + nodi, 590, 110);
  //text ("hrs", 620,110);
  //text (System.nanoTime(), 620,110);
  //text (System.currentTimeMillis(), 620,110);
  fill(0, 0, 180);
  text (nikazhmadhippu1, 80, 33,10);
  //text ("rajaguru", 980,20);
  fill(180, 0, 0);
  text (nikazhmadhippu2, 120, 33, 10);
  fill(0, 180, 0); //green
  text (nikazhmadhippu3, 160, 33,10); 
  
  fill(0, 0, 255);

}

void framerate(){
  text (frameRate, 545, 33);
  
  //text ("frame-eNNikkai / count:", 500, 55);
  //text ("Odum-nEram, nodiyil //running-duration, sec: ", 380, 40);
  text (frameCount, 630, 33);
  text (millis()/1000, 500, 33);
  fill(255, 255, 255);
}
void mouseClicked(){
  if ((mouseX>1850&&mouseX<1900)&&(mouseY>10&&mouseY<50))
     { 
       //showMessageDialog(null, "do you want to close?!!!", 
   // "Alert", ERROR_MESSAGE);
    
    int reply = showConfirmDialog(null, "want to close?!", "Usaaru / Alert",YES_NO_OPTION);
        if (reply == YES_OPTION) 
        { exit();
          showMessageDialog(null, "bye!", "Seidhi / Message", ERROR_MESSAGE);
        }
       // else {
           //showMessageDialog(null, "do u want to close?!");
           //System.exit(0);
       // }
    
  //  if (keyPressed) {
   // if (key == 'y' || key == 'Y') {exit();}}
  }
}