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;
- int a=1;
- void setup()
- {
- size(1280, 640);
- // Открываем порт, к которому подключена плата
- //контроллера используя скорость (9600 bps)
- port = new Serial(this, Serial.list()[0], 9600);
- values = new int[3];
- zoom = 1.0f;
- smooth();
- background(0);
- for(int i =41; i < 615; i = i+40){ //X
- stroke(40);
- line(12+i, height-20, 15+i, 15 );
- text(a, 12+i, height-5);
- a++;
- }
- /* for(int i = 0; i < 610; i = i + 4 ){ //Y
- line(690, height-20-i, 1200, height-20-i );
- text(a, 675, height-20-i );
- a++;
- }
- */
- }
- //Функція, яка викликається, коли з СОМ-порту приходять нові дані
- 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);
- strokeWeight(1);
- stroke(255);
- 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);
- strokeWeight(2);
- line(15, 15, 15, height-20);
- line(15, height-20, 620, height-20);
- line(620, height-20, 590, height-35); //>x
- line(620, height-20, 590, height-5); //>x
- line(15, 15, 25, 30);//>y
- line(15, 15, 5, 30);//>y
- //second
- line(690, 15, 690, height-20);
- line(690, height-20, 1200, height-20);
- line(1200, height-20, 1170, height-5); //>x
- line(1200, height-20, 1170, height-35); //>x
- line(690, 15, 700, 30);
- line(690, 15, 680, 30);
- strokeWeight(1);
- /*for(int i =41; i < 615; i = i+41){
- stroke(40);
- line(12+i, height-20, 15+i, 15 );
- }
- for(int i = 0; i < 610; i = i + 9 ){
- line(17, height-15-i, 590, height-15-i );
- }
- */
- }
- 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(480, 30, 200, 60);
- fill(255);
- textSize(18);
- text("U = " + Upoint + " mV", 500, 50);
- text("I = " + Ipoint + " mA", 500, 80);
- text("I", 35, 35);
- text("U", 610, height- 35);
- //=====================================
- //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, 30, 200, 60);
- fill(255);
- text("T = " + Tpoint + " °C", width-145, 50);
- //text(x1_1, width-145, height-300);
- text("R = " + R_out + " Om", width-145, 80);
- //text(x1_1, width-145, height-240);
- text("T", 710, 35);
- text("R", 1200, height- 35);
- R_out = String.format("%.2f", R_float);
- fill(255);
- stroke(255);
- rect(650, 0, 20, height);
- fill(0);
- stroke(0);
- x1 = int(Upoint / 1023.0f / 30 * (width-30));
- if(Ipoint > 0){
- y1 = int(height - 25 - Ipoint * 1200 / 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) + 700);
- }
- else{
- R_float = 0;
- }
- //text(x1_1, width-35, height- 105);
- //}
- //else{
- //x1_1=0;
- //}
- y1_1 = int(height - 15 - Tpoint *6 / 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