import processing.net.*;
//import processing.serial.*;
Client ennodaClient;
//Serial envazhi;
int nikazhmadhippu1, nikazhmadhippu2, nikazhmadhippu3;
int z=20;
int[] akalavu;
int[] meiyalavu;
int[] uyiralavu;
int[] akmin;
int[] uyirmin;
int[] meimin;
int akminn,akmaxx;
int uyirminn, uyirmaxx;
int meiminn, meimaxx;
int[] akmax;
int[] uyirmax;
int[] meimax;
int ullpiri;
int h=1;
//PrintWriter actual,mapped,simulate;
void setup()
{
size(displayWidth, displayHeight);
//size(1000, 550);
frameRate(60);
strokeWeight(1);
smooth(); // or noSmooth();
akalavu = new int[100];
meiyalavu = new int[100];
uyiralavu = new int[100];
akminn = 2000;
meiminn = 2000;
uyirminn = 2000;
akmaxx = -1000;
meimaxx= -1000;
uyirmaxx= -1000;
ennodaClient = new Client(this, "120.120.120.120", 265);
//String portName = Serial.list()[1];
// envazhi = new Serial(this, portName, 38400);
// actual = createWriter("unmai_actualvalues.txt");
// simulate = createWriter("mapped_for_simulation.txt");
// mapped = createWriter("marupadhippu_mappedvalues.txt");
}
void draw()
{
String ull = ennodaClient.readStringUntil('\n');
//String ull = envazhi.readStringUntil('\n');
if(ull != null)
{
int[] ullpiri = int(split(ull, ","));
nikazhmadhippu1 = int(ullpiri[0]);
nikazhmadhippu2 = int(ullpiri[1]);
nikazhmadhippu3 = int(ullpiri[2]);
// println("nikazh =", nikazhmadhippu1);
background(255);
akalavu[1]= nikazhmadhippu1;
meiyalavu[1]= nikazhmadhippu2;
uyiralavu[1]= nikazhmadhippu3;
/*actual.print(h);
actual.print("]");
actual.print(akalavu[1]);
actual.print(",");
actual.print(meiyalavu[1]);
actual.print(",");
actual.print(uyiralavu[1]);
actual.println();*/
{
for(int i = 1; i < 100; i++)
{
akalavu[i-1] = akalavu[i]; //shifting every value to previous array-element ANDDDDDDDDD storing 100 subsequent values in 100 array-elements
meiyalavu[i-1] = meiyalavu[i];
uyiralavu[i-1] = uyiralavu[i];
akminn = min(akminn, akalavu[i]);
meiminn = min(meiminn, meiyalavu[i]);
uyirminn = min(uyirminn, uyiralavu[i]);
akmaxx = max(akmaxx, akalavu[i]);
meimaxx = max(meimaxx, meiyalavu[i]);
uyirmaxx = max(uyirmaxx, uyiralavu[i]);
/* if ( akalavu[i] < akmin[i]){akmin[i] = akalavu[i]; akminn = akmin[i];}
if ( meiyalavu[i] < meimin[i]){meimin[i] = meiyalavu[i]; meiminn = meimin[i];}
if ( uyiralavu[i] < uyirmin[i]){uyirmin[i] = uyiralavu[i]; uyirminn = uyirmin [i];}*/
// println("ak =",akalavu[i]);
// println(meiyalavu[i]);
// println("a =",uyiralavu[i]);
/*simulate.print(akalavu[i]);
simulate.print(",");
simulate.print(meiyalavu[i]);
simulate.print(",");
simulate.print(uyiralavu[i]);
simulate.println();*/
}
akalavu[100-1] = int( map(nikazhmadhippu1, akminn, akmaxx, 0, height/2));
meiyalavu[100-1] = int( map(nikazhmadhippu2, meiminn, meimaxx, height/2, height));
// uyiralavu[100-1] = int( map(nikazhmadhippu3, uyirminn, uyirmaxx, 0, height));
/* mapped.print(h);
mapped.print("]");
mapped.print(akalavu[99]);
mapped.print(",");
mapped.print(meiyalavu[99]);
mapped.print(",");
mapped.print(uyiralavu[99]);
mapped.println();*/
}
{
beginShape();
strokeWeight(1);
stroke(0, 0, 250); //(rgb) colored lines, blue for z-axis
{
int j=1;
int i=1;
//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<99 && j <(z*100); i++, j= j+z)
{
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(1);
stroke(0, 250, 0); //green for x-axis
{
int j=1;
int i=1;
for (i=1, j=1; i<99 && j <(z*100); i++, j= j+z)
{
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(1);
stroke(250, 0, 0); //red for y-axis
{
int j=1;
int i=1;
for (i=1, j=1; i<99 && j <(z*100); i++, j= j+z)
{
curveVertex(j, meiyalavu[i-1]);
}
}
endShape();
}
}
// nEram();
//framerate();
name();
h++;
}
void name() {
PImage padam1, padam2, padam3, padam4, padam5, padam6, padam7, padam8, padam9, padam10, padam11;
//fill(80, 80, 200);
//text ("m.rajaguru", 1550, 30);
//fill(255, 255, 255);
//padam2 = loadImage("enperu.png");
//image(padam2, 1000, 0, 129, 29);
padam1 = loadImage("jalli3.png");
image(padam1, 5, 5, 108, 115);
// padam3 = loadImage ("rate.png");
// image(padam3, 215, 15, 325, 28);
padam4 = loadImage ("count2.png");
image(padam4, 158, 10, 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, 113, 5, 108, 115);
// padam4 = loadImage ("count2.png");
//image(padam4, 178, 5, 292, 25);
// padam8 = loadImage ("19200.png");
//image(padam8, 1500, 48, 73, 24);
//padam9 = loadImage ("14400.png");
//image(padam9, 22,10, 73, 24);
//padam10 = loadImage ("9600.png");
//image(padam10, 1500, 96, 73, 24);
//padam11 = loadImage ("vellalavu.png");
// image(padam11, 1482, 5, 108, 43);
//image(padam2, 0, 230, 100, 20);
}
void nEram(){
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 (nikazhmadhippu, 550, 535);
}
void framerate(){
text (frameRate, 546, 33);
//text ("frame-eNNikkai / count:", 500, 55);
//text ("Odum-nEram, nodiyil //running-duration, sec: ", 380, 40);
text (frameCount, 550, 60);
text (millis()/1000, 550, 85);
fill(255, 255, 255);
}
/*void keyPressed() {
if ((key == 'v') || (key == 'V'))
{
actual.flush(); // Writes the remaining data to the file
actual.close(); // Finishes the file
mapped.flush();
mapped.close();
simulate.flush();
simulate.close();
exit(); // Stops the program
}
}*/
No comments:
Post a Comment