Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.serial.*;
- Serial port; // Создание объекта класса Serial
- int val; // Данные, получаемые из сом-порта
- int[] values;
- float zoom;
- char flag = 0;
- char first_m = 1;
- String inputString = "";
- String portValue = ""; //значення, яке ми отримуємо з СОМ-порту
- String buffer = "";
- int Ipoint = 0;
- int Upoint = 0;
- int Tpoint = 0;
- //int Xpoint_1 = 0;
- //int Ypoint_1 = 0;
- int x0, y0, x1, y1;
- int x0_1, y0_1, x1_1, y1_1;
- int z = 0;
- float R_float;
- String R_out;
- void setup()
- {
- size(640, 640);
- // Открываем порт, к которому подключена плата
- //контроллера используя скорость (9600 bps)
- port = new Serial(this, Serial.list()[0], 9600);
- values = new int[3];
- zoom = 1.0f;
- smooth();
- background(0);
- }
- //Функція, яка викликається, коли з СОМ-порту приходять нові дані
- void serialEvent(Serial port)
- {
- //Зчитуємо дані з СОМ-порту і записуємо у відповідну змінну
- portValue = port.readStringUntil('\n');
- if (portValue != null) {
- flag = 1;
- inputString = portValue;
- }
- }
- void pushValue(int value) {
- for (int i=0; i<width-1; i++)
- values[i] = values[i+1];
- values[width-1] = value;
- }
- void drawLines2() {
- stroke(255);
- int displayWidth = (int) (width / zoom);
- line(x0, y0, x1, y1);
- line(x0_1, y0_1, x1_1, y1_1);
- //text(x0_1 + " " + y0_1 + " " + x1_1 + " " +Upoint/Ipoint, width-145, 50);
- x0 = x1;
- y0 = y1;
- x0_1 = x1_1;
- y0_1 = y1_1;
- // text(y1, 30, 30);
- }
- /*void drawLines3() {
- stroke(255);
- int displayWidth = (int) (width / zoom);
- line(x01, y01, x11, y11);
- x01 = x11;
- y01 = y11;
- // text(y1, 30, 30);
- }
- */
- void drawGrid() {
- stroke(255, 0, 0);
- line(15, height-350, width-15, height-350);
- line(15, height-350, 15, 15);
- line(width-15, height-350, width-30, height-360); //>x
- line(width-15, height-350, width-30, height-340); //>x
- line(15, 15, 25, 30);//>y
- line(15, 15, 5, 30);//>y
- //second
- line(15, height-15, width-15, height-15);
- line(15, height-15, 15, height-300);
- line(width-15, height-15, width-30, height-25); //>x
- line(width-15, height-15, width-30, height-5); //>x
- line(15, height-300, 25, height-285);
- line(15, height-300, 5, height-285);
- }
- void keyReleased() {
- switch (key) {
- case '+':
- zoom *= 2.0f;
- println(zoom);
- if ( (int) (width / zoom) <= 1 )
- zoom /= 2.0f;
- break;
- case '-':
- zoom /= 2.0f;
- if (zoom < 1.0f)
- zoom *= 2.0f;
- break;
- }
- }
- void draw()
- {
- //
- if (flag == 1) {
- drawGrid();
- //=====================================
- values = int(split(inputString, ","));
- Upoint=values[0];
- Tpoint=values[1];
- Ipoint=values[2];
- fill(0);
- stroke(0);
- rect( width-146, 19, width, 81);
- fill(255);
- textSize(18);
- text("U = " + Upoint + " mV", width-145, 50);
- text("I = " + Ipoint + " mA", width-145, 80);
- text("I", 35, 35);
- text("U", width-35, height- 370);
- //=====================================
- //for float R
- //rect( width-30, height-150, width, 81);
- /*Xpoint_1=values[2];
- Ypoint_1=values[0];
- */
- fill(0);
- stroke(0);
- rect( width-146, height-330, width, height-550);
- fill(255);
- text("T = " + Tpoint + " °C", width-145, height-300);
- //text(x1_1, width-145, height-300);
- text("R = " + R_out + " Om", width-145, height-270);
- //text(x1_1, width-145, height-240);
- text("T", 35, height-285);
- text("R", width-35, height- 35);
- R_out = String.format("%.2f", R_float);
- x1 = int(Upoint / 1023.0f / 30 * (width-30) + 15);
- if(Ipoint > 0){
- y1 = int(height - 350 - Ipoint * 1000 / 1023.0f / 75 * (height-30));
- }
- else{
- }
- //z=Xpoint/Ypoint;
- //if(Ipoint!=0){
- R_float = float(Upoint) / float(Ipoint*1000);
- //R_float = 1 / 2;
- if(R_float > 0){
- x1_1 = int(R_float *500 / 1023.0f * (width-30) + 15);
- }
- else{
- R_float = 0;
- }
- //text(x1_1, width-35, height- 105);
- //}
- //else{
- //x1_1=0;
- //}
- y1_1 = int(height - 15 - Tpoint *2 / 1023.0f * (height-30)); //graphik 2
- //y1_1 = int(height-Tpoint*2);
- //text(y1_1, width-145, height-240);
- //==================================================================
- if (first_m == 1)
- {
- x0 = x1;
- y0 = y1;
- x0_1 = x1_1;
- y0_1 = y1_1;
- first_m = 0;
- } else
- drawLines2();
- flag = 0;
- };
- // val = getValue();
- /*
- if (val != -1) {
- pushValue(val);
- }
- drawLines();
- */
- }
Add Comment
Please, Sign In to add comment