Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 124 lines (99 sloc) 3.112 kB
8c0edc8 now with detection...
mads hobye authored
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
Something went wrong with that request. Please try again.