├── .DS_Store ├── Arduino_sensing ├── Arduino_sensing.ino └── SendData.ino └── Processing_graph ├── Processing_graph.pde ├── SerialLink.pde └── GraphClass.pde /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Illutron/AdvancedTouchSensing/HEAD/.DS_Store -------------------------------------------------------------------------------- /Arduino_sensing/Arduino_sensing.ino: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | //**************************************************************************************** 5 | // Illutron take on Disney style capacitive touch sensor using only passives and Arduino 6 | // Dzl 2012 7 | //**************************************************************************************** 8 | 9 | 10 | // 10n 11 | // PIN 9 --[10k]-+-----10mH---+--||-- OBJECT 12 | // | | 13 | // 3.3k | 14 | // | V 1N4148 diode 15 | // GND | 16 | // | 17 | //Analog 0 ---+------+--------+ 18 | // | | 19 | // 100pf 1MOmhm 20 | // | | 21 | // GND GND 22 | 23 | 24 | 25 | #define SET(x,y) (x |=(1<=================================================================< 8 | y = 01010100 11010100 (x & y are 2 Byte integers) 9 | yMSB yLSB send seperately -> reciever joins them 10 | >=================================================================< */ 11 | 12 | yLSB=lowByte(yValue); 13 | yMSB=highByte(yValue); 14 | xLSB=lowByte(xValue); 15 | xMSB=highByte(xValue); 16 | 17 | 18 | /* >=================================================================< 19 | Only the very first Byte may be a zero, this way allows the computer 20 | to know that if a Byte recieved is a zero it must be the start byte. 21 | If data bytes actually have a value of zero, They are given the value 22 | one and the bit in the zeroByte that represents that Byte is made 23 | high. 24 | >=================================================================< */ 25 | 26 | zeroByte = 128; // 10000000 27 | 28 | if(yLSB==0){ yLSB=1; zeroByte=zeroByte+1;} // Make bit 1 high 29 | if(yMSB==0){ yMSB=1; zeroByte=zeroByte+2;} // make bit 2 high 30 | if(xLSB==0){ xLSB=1; zeroByte=zeroByte+4;} // make bit 3 high 31 | if(xMSB==0){ xMSB=1; zeroByte=zeroByte+8;} // make bit 4 high 32 | 33 | 34 | /* >=================================================================< 35 | Calculate the remainder of: sum of all the Bytes divided by 255 36 | >=================================================================< */ 37 | 38 | Checksum = (Command + yMSB + yLSB + xMSB + xLSB + zeroByte)%255; 39 | 40 | if( Checksum !=0 ){ 41 | Serial.write(byte(0)); // send start bit 42 | Serial.write(byte(Command)); // command eg: Which Graph is this data for 43 | 44 | Serial.write(byte(yMSB)); // Y value's most significant byte 45 | Serial.write(byte(yLSB)); // Y value's least significant byte 46 | Serial.write(byte(xMSB)); // X value's most significant byte 47 | Serial.write(byte(xLSB)); // X value's least significant byte 48 | 49 | Serial.write(byte(zeroByte)); // Which values have a zero value 50 | Serial.write(byte(Checksum)); // Error Checking Byte 51 | } 52 | } 53 | 54 | 55 | 56 | 57 | void PlottArray(unsigned int Cmd,float Array1[],float Array2[]){ 58 | 59 | SendData(Cmd+1, 1,1); // Tell PC an array is about to be sent 60 | delay(1); 61 | for(int x=0; x < sizeOfArray; x++){ // Send the arrays 62 | SendData(Cmd, round(Array1[x]),round(Array2[x])); 63 | //delay(1); 64 | } 65 | 66 | SendData(Cmd+2, 1,1); // Confirm arrrays have been sent 67 | } 68 | 69 | -------------------------------------------------------------------------------- /Processing_graph/Processing_graph.pde: -------------------------------------------------------------------------------- 1 | Graph MyArduinoGraph = new Graph(150, 80, 500, 300, color (200, 20, 20)); 2 | float[] gestureOne=null; 3 | float[] gestureTwo = null; 4 | float[] gestureThree = null; 5 | 6 | float[][] gesturePoints = new float[4][2]; 7 | float[] gestureDist = new float[4]; 8 | String[] names = {"Nothing", "Touch", "Grab","In water"}; 9 | void setup() { 10 | 11 | size(1000, 500); 12 | 13 | MyArduinoGraph.xLabel="Readnumber"; 14 | MyArduinoGraph.yLabel="Amp"; 15 | MyArduinoGraph.Title=" Graph"; 16 | noLoop(); 17 | PortSelected=1; /* ==================================================================== 18 | adjust this (0,1,2...) until the correct port is selected 19 | In my case 2 for COM4, after I look at the Serial.list() string 20 | println( Serial.list() ); 21 | [0] "COM1" 22 | [1] "COM2" 23 | [2] "COM4" 24 | ==================================================================== */ 25 | SerialPortSetup(); // speed of 115200 bps etc. 26 | } 27 | 28 | 29 | void draw() { 30 | 31 | background(255); 32 | 33 | /* ==================================================================== 34 | Print the graph 35 | ==================================================================== */ 36 | 37 | if ( DataRecieved3 ) { 38 | pushMatrix(); 39 | pushStyle(); 40 | MyArduinoGraph.yMax=1000; 41 | MyArduinoGraph.yMin=-200; 42 | MyArduinoGraph.xMax=int (max(Time3)); 43 | MyArduinoGraph.DrawAxis(); 44 | MyArduinoGraph.smoothLine(Time3, Voltage3); 45 | popStyle(); 46 | popMatrix(); 47 | 48 | float gestureOneDiff =0; 49 | float gestureTwoDiff =0; 50 | float gestureThreeDiff =0; 51 | 52 | /* ==================================================================== 53 | Gesture compare 54 | ==================================================================== */ 55 | float totalDist = 0; 56 | int currentMax = 0; 57 | float currentMaxValue = -1; 58 | for (int i = 0; i < 4;i++) 59 | 60 | { 61 | 62 | // gesturePoints[i][0] = 63 | if (mousePressed && mouseX > 750 && mouseX<800 && mouseY > 100*(i+1) && mouseY < 100*(i+1) + 50) 64 | { 65 | fill(255, 0, 0); 66 | 67 | gesturePoints[i][0] = Time3[MyArduinoGraph.maxI]; 68 | gesturePoints[i][1] = Voltage3[MyArduinoGraph.maxI]; 69 | } 70 | else 71 | { 72 | fill(255, 255, 255); 73 | } 74 | 75 | //calucalte individual dist 76 | gestureDist[i] = dist(Time3[MyArduinoGraph.maxI], Voltage3[MyArduinoGraph.maxI], gesturePoints[i][0], gesturePoints[i][1]); 77 | totalDist = totalDist + gestureDist[i]; 78 | if(gestureDist[i] < currentMaxValue || i == 0) 79 | { 80 | currentMax = i; 81 | currentMaxValue = gestureDist[i]; 82 | } 83 | } 84 | totalDist=totalDist /3; 85 | 86 | for (int i = 0; i < 4;i++) 87 | { 88 | float currentAmmount = 0; 89 | currentAmmount = 1-gestureDist[i]/totalDist; 90 | if(currentMax == i) 91 | { 92 | fill(0,0,0); 93 | // text(names[i],50,450); 94 | fill(currentAmmount*255.0f, 0, 0); 95 | 96 | 97 | } 98 | else 99 | { 100 | fill(255,255,255); 101 | } 102 | 103 | stroke(0, 0, 0); 104 | rect(750, 100 * (i+1), 50, 50); 105 | fill(0,0,0); 106 | textSize(30); 107 | text(names[i],810,100 * (i+1)+25); 108 | 109 | fill(255, 0, 0); 110 | // rect(800,100* (i+1), max(0,currentAmmount*50),50); 111 | } 112 | 113 | 114 | } 115 | } 116 | 117 | void stop() 118 | { 119 | 120 | myPort.stop(); 121 | super.stop(); 122 | } 123 | 124 | -------------------------------------------------------------------------------- /Processing_graph/SerialLink.pde: -------------------------------------------------------------------------------- 1 | import processing.serial.*; 2 | int SerialPortNumber=2; 3 | int PortSelected=2; 4 | 5 | /* ================================================================================= 6 | Global variables 7 | =================================================================================*/ 8 | 9 | int xValue, yValue, Command; 10 | boolean Error=true; 11 | 12 | boolean UpdateGraph=true; 13 | int lineGraph; 14 | int ErrorCounter=0; 15 | int TotalRecieved=0; 16 | 17 | /* ================================================================================= 18 | Local variables 19 | =================================================================================*/ 20 | boolean DataRecieved1=false, DataRecieved2=false, DataRecieved3=false; 21 | 22 | float[] DynamicArrayTime1, DynamicArrayTime2, DynamicArrayTime3; 23 | float[] Time1, Time2, Time3; 24 | float[] Voltage1, Voltage2, Voltage3; 25 | float[] current; 26 | float[] DynamicArray1, DynamicArray2, DynamicArray3; 27 | 28 | float[] PowerArray= new float[0]; // Dynamic arrays that will use the append() 29 | float[] DynamicArrayPower = new float[0]; // function to add values 30 | float[] DynamicArrayTime= new float[0]; 31 | 32 | String portName; 33 | String[] ArrayOfPorts=new String[SerialPortNumber]; 34 | 35 | boolean DataRecieved=false, Data1Recieved=false, Data2Recieved=false; 36 | int incrament=0; 37 | 38 | int NumOfSerialBytes=8; // The size of the buffer array 39 | int[] serialInArray = new int[NumOfSerialBytes]; // Buffer array 40 | int serialCount = 0; // A count of how many bytes received 41 | int xMSB, xLSB, yMSB, yLSB; // Bytes of data 42 | 43 | Serial myPort; // The serial port object 44 | 45 | 46 | /* ================================================================================= 47 | A once off serail port setup function. In this case the selection of the speed, 48 | the serial port and clearing the serial port buffer 49 | =================================================================================*/ 50 | 51 | void SerialPortSetup() { 52 | 53 | // text(Serial.list().length,200,200); 54 | 55 | portName= Serial.list()[PortSelected]; 56 | // println( Serial.list()); 57 | ArrayOfPorts=Serial.list(); 58 | println(ArrayOfPorts); 59 | myPort = new Serial(this, portName, 115200); 60 | delay(50); 61 | myPort.clear(); 62 | myPort.buffer(20); 63 | } 64 | 65 | /* ============================================================ 66 | serialEvent will be called when something is sent to the 67 | serial port being used. 68 | ============================================================ */ 69 | 70 | void serialEvent(Serial myPort) { 71 | 72 | while (myPort.available ()>0) 73 | { 74 | /* ============================================================ 75 | Read the next byte that's waiting in the buffer. 76 | ============================================================ */ 77 | 78 | int inByte = myPort.read(); 79 | 80 | if (inByte==0)serialCount=0; 81 | 82 | if (inByte>255) { 83 | println(" inByte = "+inByte); 84 | exit(); 85 | } 86 | 87 | // Add the latest byte from the serial port to array: 88 | 89 | serialInArray[serialCount] = inByte; 90 | serialCount++; 91 | 92 | Error=true; 93 | if (serialCount >= NumOfSerialBytes ) { 94 | serialCount = 0; 95 | 96 | TotalRecieved++; 97 | 98 | int Checksum=0; 99 | 100 | // Checksum = (Command + yMSB + yLSB + xMSB + xLSB + zeroByte)%255; 101 | for (int x=0; x=====< combine bytes to form large integers >==================< // 144 | 145 | Command = serialInArray[1]; 146 | 147 | xValue = xMSB << 8 | xLSB; // Get xValue from yMSB & yLSB 148 | yValue = yMSB << 8 | yLSB; // Get yValue from xMSB & xLSB 149 | 150 | // println(Command+ " "+xValue+" "+ yValue+" " ); 151 | 152 | /* 153 | How that works: if xMSB = 10001001 and xLSB = 0100 0011 154 | xMSB << 8 = 10001001 00000000 (shift xMSB left by 8 bits) 155 | xLSB = 01000011 156 | xLSB | xMSB = 10001001 01000011 combine the 2 bytes using the logic or | 157 | xValue = 10001001 01000011 now xValue is a 2 byte number 0 -> 65536 158 | */ 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | /* ================================================================== 167 | Command, xValue & yValue have now been recieved from the chip 168 | ================================================================== */ 169 | 170 | switch(Command) { 171 | 172 | 173 | /* ================================================================== 174 | Recieve array1 and array2 from chip, update oscilloscope 175 | ================================================================== */ 176 | 177 | case 1: // Data is added to dynamic arrays 178 | DynamicArrayTime3=append( DynamicArrayTime3, (xValue) ); 179 | DynamicArray3=append( DynamicArray3, (yValue) ); 180 | 181 | break; 182 | 183 | case 2: // An array of unknown size is about to be recieved, empty storage arrays 184 | DynamicArrayTime3= new float[0]; 185 | DynamicArray3= new float[0]; 186 | break; 187 | 188 | case 3: // Array has finnished being recieved, update arrays being drawn 189 | Time3=DynamicArrayTime3; 190 | Voltage3=DynamicArray3; 191 | // println(Voltage3.length); 192 | DataRecieved3=true; 193 | break; 194 | 195 | /* ================================================================== 196 | Recieve array2 and array3 from chip 197 | ================================================================== */ 198 | 199 | 200 | case 4: // Data is added to dynamic arrays 201 | DynamicArrayTime2=append( DynamicArrayTime2, xValue ); 202 | DynamicArray2=append( DynamicArray2, (yValue-16000.0)/32000.0*20.0 ); 203 | break; 204 | 205 | case 5: // An array of unknown size is about to be recieved, empty storage arrays 206 | DynamicArrayTime2= new float[0]; 207 | DynamicArray2= new float[0]; 208 | break; 209 | 210 | case 6: // Array has finnished being recieved, update arrays being drawn 211 | Time2=DynamicArrayTime2; 212 | current=DynamicArray2; 213 | DataRecieved2=true; 214 | break; 215 | 216 | /* ================================================================== 217 | Recieve a value of calculated power consumption & add it to the 218 | PowerArray. 219 | ================================================================== */ 220 | case 20: 221 | PowerArray=append( PowerArray, yValue ); 222 | 223 | break; 224 | 225 | case 21: 226 | DynamicArrayTime=append( DynamicArrayTime, xValue ); 227 | DynamicArrayPower=append( DynamicArrayPower, yValue ); 228 | 229 | 230 | 231 | break; 232 | } 233 | } 234 | } 235 | redraw(); 236 | // } 237 | } 238 | 239 | 240 | -------------------------------------------------------------------------------- /Processing_graph/GraphClass.pde: -------------------------------------------------------------------------------- 1 | 2 | /* ================================================================================= 3 | The Graph class contains functions and variables that have been created to draw 4 | graphs. Here is a quick list of functions within the graph class: 5 | 6 | Graph(int x, int y, int w, int h,color k) 7 | DrawAxis() 8 | Bar([]) 9 | smoothLine([][]) 10 | DotGraph([][]) 11 | LineGraph([][]) 12 | 13 | =================================================================================*/ 14 | 15 | 16 | class Graph 17 | { 18 | float maxY = 0; 19 | float maxX = 0; 20 | int maxI = 0; 21 | boolean Dot=true; // Draw dots at each data point if true 22 | boolean RightAxis; // Draw the next graph using the right axis if true 23 | boolean ErrorFlag=false; // If the time array isn't in ascending order, make true 24 | boolean ShowMouseLines=true; // Draw lines and give values of the mouse position 25 | 26 | int xDiv=5, yDiv=5; // Number of sub divisions 27 | int xPos, yPos; // location of the top left corner of the graph 28 | int Width, Height; // Width and height of the graph 29 | 30 | 31 | color GraphColor; 32 | color BackgroundColor=color(255); 33 | color StrokeColor=color(180); 34 | 35 | String Title="Title"; // Default titles 36 | String xLabel="x - Label"; 37 | String yLabel="y - Label"; 38 | 39 | float yMax=1024, yMin=0; // Default axis dimensions 40 | float xMax=10, xMin=0; 41 | float yMaxRight=1024, yMinRight=0; 42 | 43 | // PFont Font; // Selected font used for text 44 | 45 | // int Peakcounter=0,nPeakcounter=0; 46 | 47 | Graph(int x, int y, int w, int h, color k) { // The main declaration function 48 | xPos = x; 49 | yPos = y; 50 | Width = w; 51 | Height = h; 52 | GraphColor = k; 53 | } 54 | 55 | 56 | void DrawAxis() { 57 | 58 | /* ========================================================================================= 59 | Main axes Lines, Graph Labels, Graph Background 60 | ========================================================================================== */ 61 | 62 | fill(BackgroundColor); 63 | color(0); 64 | stroke(StrokeColor); 65 | strokeWeight(1); 66 | int t=60; 67 | 68 | rect(xPos-t*1.6, yPos-t, Width+t*2.5, Height+t*2); // outline 69 | textAlign(CENTER); 70 | textSize(18); 71 | float c=textWidth(Title); 72 | fill(BackgroundColor); 73 | color(0); 74 | stroke(0); 75 | strokeWeight(1); 76 | rect(xPos+Width/2-c/2, yPos-35, c, 0); // Heading Rectangle 77 | 78 | fill(0); 79 | text(Title, xPos+Width/2, yPos-37); // Heading Title 80 | textAlign(CENTER); 81 | textSize(14); 82 | text(xLabel, xPos+Width/2, yPos+Height+t/1.5); // x-axis Label 83 | 84 | rotate(-PI/2); // rotate -90 degrees 85 | text(yLabel, -yPos-Height/2, xPos-t*1.6+20); // y-axis Label 86 | rotate(PI/2); // rotate back 87 | 88 | textSize(10); 89 | noFill(); 90 | stroke(0); 91 | smooth(); 92 | strokeWeight(1); 93 | //Edges 94 | line(xPos-3, yPos+Height, xPos-3, yPos); // y-axis line 95 | line(xPos-3, yPos+Height, xPos+Width+5, yPos+Height); // x-axis line 96 | 97 | stroke(200); 98 | if (yMin<0) { 99 | line(xPos-7, // zero line 100 | yPos+Height-(abs(yMin)/(yMax-yMin))*Height, // 101 | xPos+Width, 102 | yPos+Height-(abs(yMin)/(yMax-yMin))*Height 103 | ); 104 | } 105 | 106 | if (RightAxis) { // Right-axis line 107 | stroke(0); 108 | line(xPos+Width+3, yPos+Height, xPos+Width+3, yPos); 109 | } 110 | 111 | /* ========================================================================================= 112 | Sub-devisions for both axes, left and right 113 | ========================================================================================== */ 114 | 115 | stroke(0); 116 | 117 | for (int x=0; x<=xDiv; x++) { 118 | 119 | /* ========================================================================================= 120 | x-axis 121 | ========================================================================================== */ 122 | 123 | line(float(x)/xDiv*Width+xPos-3, yPos+Height, // x-axis Sub devisions 124 | float(x)/xDiv*Width+xPos-3, yPos+Height+5); 125 | 126 | textSize(10); // x-axis Labels 127 | String xAxis=str(xMin+float(x)/xDiv*(xMax-xMin)); // the only way to get a specific number of decimals 128 | String[] xAxisMS=split(xAxis, '.'); // is to split the float into strings 129 | text(xAxisMS[0]+"."+xAxisMS[1].charAt(0), // ... 130 | float(x)/xDiv*Width+xPos-3, yPos+Height+15); // x-axis Labels 131 | } 132 | 133 | 134 | /* ========================================================================================= 135 | left y-axis 136 | ========================================================================================== */ 137 | 138 | for (int y=0; y<=yDiv; y++) { 139 | line(xPos-3, float(y)/yDiv*Height+yPos, // ... 140 | xPos-7, float(y)/yDiv*Height+yPos); // y-axis lines 141 | 142 | textAlign(RIGHT); 143 | fill(20); 144 | 145 | String yAxis=str(yMin+float(y)/yDiv*(yMax-yMin)); // Make y Label a string 146 | String[] yAxisMS=split(yAxis, '.'); // Split string 147 | 148 | text(yAxisMS[0]+"."+yAxisMS[1].charAt(0), // ... 149 | xPos-15, float(yDiv-y)/yDiv*Height+yPos+3); // y-axis Labels 150 | 151 | 152 | /* ========================================================================================= 153 | right y-axis 154 | ========================================================================================== */ 155 | 156 | if (RightAxis) { 157 | 158 | color(GraphColor); 159 | stroke(GraphColor); 160 | fill(20); 161 | 162 | line(xPos+Width+3, float(y)/yDiv*Height+yPos, // ... 163 | xPos+Width+7, float(y)/yDiv*Height+yPos); // Right Y axis sub devisions 164 | 165 | textAlign(LEFT); 166 | 167 | String yAxisRight=str(yMinRight+float(y)/ // ... 168 | yDiv*(yMaxRight-yMinRight)); // convert axis values into string 169 | String[] yAxisRightMS=split(yAxisRight, '.'); // 170 | 171 | text(yAxisRightMS[0]+"."+yAxisRightMS[1].charAt(0), // Right Y axis text 172 | xPos+Width+15, float(yDiv-y)/yDiv*Height+yPos+3); // it's x,y location 173 | 174 | noFill(); 175 | } 176 | stroke(0); 177 | } 178 | } 179 | 180 | 181 | /* ========================================================================================= 182 | Bar graph 183 | ========================================================================================== */ 184 | 185 | void Bar(float[] a, int from, int to) { 186 | 187 | 188 | stroke(GraphColor); 189 | fill(GraphColor); 190 | 191 | if (from<0) { // If the From or To value is out of bounds 192 | for (int x=0; x Make sure time array doesn't decrease (go back in time) 302 | ===========================================================================*/ 303 | if (ix[i+1]) { 305 | 306 | ErrorFlag=true; 307 | } 308 | } 309 | 310 | /* ================================================================================= 311 | First and last bits can't be part of the curve, no points before first bit, 312 | none after last bit. So a streight line is drawn instead 313 | ================================================================================= */ 314 | 315 | if (i==0 || i==x.length-2)line(xPos+(x[i]-x[0])/(x[x.length-1]-x[0])*Width, 316 | yPos+Height-(y[i]/(yMax-yMin)*Height)+(yMin)/(yMax-yMin)*Height, 317 | xPos+(x[i+1]-x[0])/(x[x.length-1]-x[0])*Width, 318 | yPos+Height-(y[i+1]/(yMax-yMin)*Height)+(yMin)/(yMax-yMin)*Height); 319 | 320 | /* ================================================================================= 321 | For the rest of the array a curve (spline curve) can be created making the graph 322 | smooth. 323 | ================================================================================= */ 324 | 325 | curveVertex( xPos+(x[i]-x[0])/(x[x.length-1]-x[0])*Width, 326 | yPos+Height-(y[i]/(yMax-yMin)*Height)+(yMin)/(yMax-yMin)*Height); 327 | 328 | /* ================================================================================= 329 | If the Dot option is true, Place a dot at each data point. 330 | ================================================================================= */ 331 | if (i == maxI) 332 | { 333 | ellipse( 334 | xPos+(x[i]-x[0])/(x[x.length-1]-x[0])*Width, 335 | yPos+Height-(y[i]/(yMax-yMin)*Height)+(yMin)/(yMax-yMin)*Height, 336 | 20, 20 337 | ); 338 | } 339 | if (Dot)ellipse( 340 | xPos+(x[i]-x[0])/(x[x.length-1]-x[0])*Width, 341 | yPos+Height-(y[i]/(yMax-yMin)*Height)+(yMin)/(yMax-yMin)*Height, 342 | 2, 2 343 | ); 344 | 345 | /* ================================================================================= 346 | Highlights points closest to Mouse X position 347 | =================================================================================*/ 348 | 349 | if ( abs(mouseX-(xPos+(x[i]-x[0])/(x[x.length-1]-x[0])*Width))<5 ) { 350 | 351 | 352 | float yLinePosition = yPos+Height-(y[i]/(yMax-yMin)*Height)+(yMin)/(yMax-yMin)*Height; 353 | float xLinePosition = xPos+(x[i]-x[0])/(x[x.length-1]-x[0])*Width; 354 | strokeWeight(1); 355 | stroke(240); 356 | // line(xPos,yLinePosition,xPos+Width,yLinePosition); 357 | strokeWeight(2); 358 | stroke(GraphColor); 359 | 360 | ellipse(xLinePosition, yLinePosition, 4, 4); 361 | } 362 | } 363 | 364 | endShape(); 365 | 366 | yMax=tempyMax; 367 | yMin=tempyMin; 368 | float xAxisTitleWidth=textWidth(str(map(xlocation, xPos, xPos+Width, x[0], x[x.length-1]))); 369 | 370 | 371 | if ((mouseX>xPos&mouseX<(xPos+Width))&(mouseY>yPos&mouseY<(yPos+Height))) { 372 | if (ShowMouseLines) { 373 | // if(mouseXxPos+Width)xlocation=xPos+Width; 375 | else xlocation=mouseX; 376 | stroke(200); 377 | strokeWeight(0.5); 378 | fill(255); 379 | color(50); 380 | // Rectangle and x position 381 | line(xlocation, yPos, xlocation, yPos+Height); 382 | rect(xlocation-xAxisTitleWidth/2-10, yPos+Height-16, xAxisTitleWidth+20, 12); 383 | 384 | textAlign(CENTER); 385 | fill(160); 386 | text(map(xlocation, xPos, xPos+Width, x[0], x[x.length-1]), xlocation, yPos+Height-6); 387 | 388 | // if(mouseYyPos+Height)ylocation=yPos+Height; 390 | else ylocation=mouseY; 391 | 392 | // Rectangle and y position 393 | stroke(200); 394 | strokeWeight(0.5); 395 | fill(255); 396 | color(50); 397 | 398 | line(xPos, ylocation, xPos+Width, ylocation); 399 | int yAxisTitleWidth=int(textWidth(str(map(ylocation, yPos, yPos+Height, y[0], y[y.length-1]))) ); 400 | rect(xPos-15+3, ylocation-6, -60, 12); 401 | 402 | textAlign(RIGHT); 403 | fill(GraphColor);//StrokeColor 404 | // text(map(ylocation,yPos+Height,yPos,yMin,yMax),xPos+Width+3,yPos+Height+4); 405 | text(map(ylocation, yPos+Height, yPos, yMin, yMax), xPos -15, ylocation+4); 406 | if (RightAxis) { 407 | 408 | stroke(200); 409 | strokeWeight(0.5); 410 | fill(255); 411 | color(50); 412 | 413 | rect(xPos+Width+15-3, ylocation-6, 60, 12); 414 | textAlign(LEFT); 415 | fill(160); 416 | text(map(ylocation, yPos+Height, yPos, yMinRight, yMaxRight), xPos+Width+15, ylocation+4); 417 | } 418 | noStroke(); 419 | noFill(); 420 | } 421 | } 422 | } 423 | 424 | 425 | void smoothLine(float[] x, float[] y, float[] z, float[] a ) { 426 | GraphColor=color(188, 53, 53); 427 | smoothLine(x, y); 428 | GraphColor=color(193-100, 216-100, 16); 429 | smoothLine(z, a); 430 | } 431 | } 432 | 433 | 434 | --------------------------------------------------------------------------------