SHOW:
|
|
- or go back to the newest paste.
1 | import processing.serial.*; | |
2 | Serial port; // Создание объекта класса Serial | |
3 | int val; // Данные, получаемые из сом-порта | |
4 | int[] values; | |
5 | float zoom; | |
6 | char flag = 0; | |
7 | char first_m = 1; | |
8 | String inputString = ""; | |
9 | ||
10 | String portValue = ""; //значення, яке ми отримуємо з СОМ-порту | |
11 | String buffer = ""; | |
12 | int Ipoint = 0; | |
13 | int Upoint = 0; | |
14 | int Tpoint = 0; | |
15 | //int Xpoint_1 = 0; | |
16 | //int Ypoint_1 = 0; | |
17 | ||
18 | int x0, y0, x1, y1; | |
19 | int x0_1, y0_1, x1_1, y1_1; | |
20 | int z = 0; | |
21 | float R_float; | |
22 | String R_out; | |
23 | int a=1; | |
24 | ||
25 | void setup() | |
26 | { | |
27 | size(1280, 640); | |
28 | ||
29 | ||
30 | // Открываем порт, к которому подключена плата | |
31 | ||
32 | //контроллера используя скорость (9600 bps) | |
33 | port = new Serial(this, Serial.list()[0], 9600); | |
34 | values = new int[3]; | |
35 | zoom = 1.0f; | |
36 | smooth(); | |
37 | ||
38 | background(0); | |
39 | ||
40 | for(int i =41; i < 615; i = i+40){ //X | |
41 | stroke(40); | |
42 | line(12+i, height-20, 15+i, 15 ); | |
43 | ||
44 | ||
45 | text(a, 12+i, height-5); | |
46 | a++; | |
47 | ||
48 | } | |
49 | ||
50 | ||
51 | /* for(int i = 0; i < 610; i = i + 4 ){ //Y | |
52 | line(690, height-20-i, 1200, height-20-i ); | |
53 | text(a, 675, height-20-i ); | |
54 | a++; | |
55 | } | |
56 | */ | |
57 | ||
58 | ||
59 | } | |
60 | ||
61 | ||
62 | //Функція, яка викликається, коли з СОМ-порту приходять нові дані | |
63 | void serialEvent(Serial port) | |
64 | { | |
65 | //Зчитуємо дані з СОМ-порту і записуємо у відповідну змінну | |
66 | portValue = port.readStringUntil('\n'); | |
67 | ||
68 | ||
69 | if (portValue != null) { | |
70 | ||
71 | flag = 1; | |
72 | inputString = portValue; | |
73 | } | |
74 | } | |
75 | ||
76 | ||
77 | ||
78 | ||
79 | void pushValue(int value) { | |
80 | for (int i=0; i<width-1; i++) | |
81 | values[i] = values[i+1]; | |
82 | values[width-1] = value; | |
83 | } | |
84 | ||
85 | ||
86 | void drawLines2() { | |
87 | stroke(255); | |
88 | ||
89 | int displayWidth = (int) (width / zoom); | |
90 | ||
91 | strokeWeight(1); | |
92 | stroke(255); | |
93 | line(x0, y0, x1, y1); | |
94 | line(x0_1, y0_1, x1_1, y1_1); | |
95 | //text(x0_1 + " " + y0_1 + " " + x1_1 + " " +Upoint/Ipoint, width-145, 50); | |
96 | x0 = x1; | |
97 | y0 = y1; | |
98 | ||
99 | x0_1 = x1_1; | |
100 | y0_1 = y1_1; | |
101 | ||
102 | ||
103 | // text(y1, 30, 30); | |
104 | } | |
105 | ||
106 | /*void drawLines3() { | |
107 | stroke(255); | |
108 | ||
109 | int displayWidth = (int) (width / zoom); | |
110 | ||
111 | ||
112 | line(x01, y01, x11, y11); | |
113 | x01 = x11; | |
114 | y01 = y11; | |
115 | ||
116 | ||
117 | // text(y1, 30, 30); | |
118 | } | |
119 | */ | |
120 | ||
121 | ||
122 | ||
123 | void drawGrid() { | |
124 | stroke(255, 0, 0); | |
125 | strokeWeight(2); | |
126 | line(15, 15, 15, height-20); | |
127 | line(15, height-20, 620, height-20); | |
128 | line(620, height-20, 590, height-35); //>x | |
129 | line(620, height-20, 590, height-5); //>x | |
130 | line(15, 15, 25, 30);//>y | |
131 | line(15, 15, 5, 30);//>y | |
132 | ||
133 | ||
134 | ||
135 | //second | |
136 | line(690, 15, 690, height-20); | |
137 | line(690, height-20, 1200, height-20); | |
138 | line(1200, height-20, 1170, height-5); //>x | |
139 | line(1200, height-20, 1170, height-35); //>x | |
140 | line(690, 15, 700, 30); | |
141 | line(690, 15, 680, 30); | |
142 | strokeWeight(1); | |
143 | ||
144 | /*for(int i =41; i < 615; i = i+41){ | |
145 | stroke(40); | |
146 | line(12+i, height-20, 15+i, 15 ); | |
147 | } | |
148 | ||
149 | for(int i = 0; i < 610; i = i + 9 ){ | |
150 | line(17, height-15-i, 590, height-15-i ); | |
151 | } | |
152 | */ | |
153 | ||
154 | } | |
155 | void keyReleased() { | |
156 | switch (key) { | |
157 | case '+': | |
158 | zoom *= 2.0f; | |
159 | println(zoom); | |
160 | if ( (int) (width / zoom) <= 1 ) | |
161 | zoom /= 2.0f; | |
162 | break; | |
163 | case '-': | |
164 | zoom /= 2.0f; | |
165 | if (zoom < 1.0f) | |
166 | zoom *= 2.0f; | |
167 | break; | |
168 | } | |
169 | } | |
170 | ||
171 | void draw() | |
172 | { | |
173 | ||
174 | ||
175 | // | |
176 | ||
177 | ||
178 | if (flag == 1) { | |
179 | ||
180 | drawGrid(); | |
181 | ||
182 | ||
183 | ||
184 | ||
185 | //===================================== | |
186 | values = int(split(inputString, ",")); | |
187 | ||
188 | Upoint=values[0]; | |
189 | Tpoint=values[1]; | |
190 | Ipoint=values[2]; | |
191 | ||
192 | fill(0); | |
193 | stroke(0); | |
194 | rect(480, 30, 200, 60); | |
195 | fill(255); | |
196 | textSize(18); | |
197 | text("U = " + Upoint + " mV", 500, 50); | |
198 | text("I = " + Ipoint + " mA", 500, 80); | |
199 | text("I", 35, 35); | |
200 | text("U", 610, height- 35); | |
201 | //===================================== | |
202 | //for float R | |
203 | //rect( width-30, height-150, width, 81); | |
204 | ||
205 | ||
206 | /*Xpoint_1=values[2]; | |
207 | Ypoint_1=values[0]; | |
208 | */ | |
209 | fill(0); | |
210 | stroke(0); | |
211 | rect( width-146, 30, 200, 60); | |
212 | fill(255); | |
213 | text("T = " + Tpoint + " °C", width-145, 50); | |
214 | //text(x1_1, width-145, height-300); | |
215 | text("R = " + R_out + " Om", width-145, 80); | |
216 | //text(x1_1, width-145, height-240); | |
217 | text("T", 710, 35); | |
218 | text("R", 1200, height- 35); | |
219 | R_out = String.format("%.2f", R_float); | |
220 | ||
221 | ||
222 | fill(255); | |
223 | stroke(255); | |
224 | rect(650, 0, 20, height); | |
225 | fill(0); | |
226 | stroke(0); | |
227 | ||
228 | ||
229 | ||
230 | ||
231 | x1 = int(Upoint / 1023.0f / 30 * (width-30)); | |
232 | if(Ipoint > 0){ | |
233 | y1 = int(height - 25 - Ipoint * 1200 / 1023.0f / 75 * (height-30)); | |
234 | } | |
235 | else{ | |
236 | ||
237 | } | |
238 | ||
239 | //z=Xpoint/Ypoint; | |
240 | //if(Ipoint!=0){ | |
241 | R_float = float(Upoint) / float(Ipoint*1000); | |
242 | //R_float = 1 / 2; | |
243 | ||
244 | if(R_float > 0){ | |
245 | x1_1 = int(R_float *500 / 1023.0f * (width-30) + 700); | |
246 | } | |
247 | else{ | |
248 | R_float = 0; | |
249 | } | |
250 | //text(x1_1, width-35, height- 105); | |
251 | ||
252 | //} | |
253 | //else{ | |
254 | //x1_1=0; | |
255 | //} | |
256 | y1_1 = int(height - 15 - Tpoint *6 / 1023.0f * (height-30)); //graphik 2 | |
257 | //y1_1 = int(height-Tpoint*2); | |
258 | ||
259 | //text(y1_1, width-145, height-240); | |
260 | ||
261 | //================================================================== | |
262 | if (first_m == 1) | |
263 | { | |
264 | x0 = x1; | |
265 | y0 = y1; | |
266 | ||
267 | x0_1 = x1_1; | |
268 | y0_1 = y1_1; | |
269 | first_m = 0; | |
270 | } else | |
271 | drawLines2(); | |
272 | flag = 0; | |
273 | }; | |
274 | ||
275 | // val = getValue(); | |
276 | /* | |
277 | if (val != -1) { | |
278 | pushValue(val); | |
279 | } | |
280 | drawLines(); | |
281 | */ | |
282 | } |