Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.serial.*;
- Serial myPort;
- PImage img1;
- PImage img2;
- PImage img3;
- PFont font;
- int Gear= 0;
- int Brzina =0;
- int Ulje =1;
- int RPM =0;
- int Temperatura =0;
- int t=255;
- void setup() {
- size(1280, 720,P2D);
- img1 = loadImage("1.png");
- img2 = loadImage("2.png");
- img3 = loadImage("3.png");
- frameRate(100);
- myPort = new Serial(this, "COM10", 9600); //Prepoznavanje ulaznih bitova
- font = loadFont("Open24DisplaySt-48.vlw");
- myPort.bufferUntil(',');
- }
- void draw() {
- image(img2,0,0);
- //RPM
- if (RPM <= 7000 ){fill(RPM/27.46,255,0); stroke(RPM/27.46,255,0);}
- else if (RPM > 7000){fill(255,417.32-RPM/43.13,0); stroke(255,417.32-RPM/43.13,0);}
- float c = map(RPM,0,7000,89,270);
- if (RPM <= 7000){ arc(230, 374, 437, 437, radians(89),radians(c), CENTER); }
- else if (RPM > 5000){
- arc(230, 374, 437, 437, radians(89),radians(270), CENTER);}
- float j = map(RPM,7001,18000,1,720);
- if (RPM < 18001 && RPM > 7000){
- rect(229,148, j, 95); }
- else if (RPM > 17999){rect(229,148, 617, 95);}
- image(img3,0,0);
- //Brzina
- //fill(#922528);
- //stroke(#922528);
- float a = map(Brzina,20,260,133,406);
- fill(203,62-Brzina/4.1935,62-Brzina/4.1935);
- stroke(203,62-Brzina/4.1935,62-Brzina/4.1935);
- arc(1042, 367, 444, 444, radians(133),radians(a), CENTER);
- //Ulje
- t=t-15;
- if (t<15){t=255;}
- if (Ulje == 1){ fill(255,t,t); ellipse(790, 290, 55, 55); }
- else if (Ulje == 0){ fill(#FFFFFF); ellipse(790, 290, 55, 55);}
- fill(#FFFFFF);
- image(img1,0,0);
- if (RPM < 10) { textFont(font,80);text(RPM,227,400); } //Brzina
- else if (RPM > 9 && RPM < 100) { textFont(font,80);text(RPM,207,400); }
- else if (RPM > 99 && RPM < 1000) { textFont(font,80);text(RPM,195,400); }
- else if (RPM > 999 && RPM < 10000) { textFont(font,80);text(RPM,175,400); }
- else if (RPM > 9999 && RPM < 18001) { textFont(font,80);text(RPM,155,400); }
- if (Gear >= 1 && Gear <= 6) { textFont(font,160); text(Gear,1013,428); }
- else if (Gear == 7) { textFont(font,160); text("N",1011,428); }
- if (Brzina > 0 && Brzina < 10) { textFont(font,65);text(Brzina,320,570); } //Brzina
- else if (Brzina > 9 && Brzina < 100) { textFont(font,65);text(Brzina,300,570); }
- else if (Brzina > 99 && Brzina < 300) { textFont(font,65);text(Brzina,280,570); }
- if (Temperatura > 0 && Temperatura < 10) { textFont(font,65); text(Temperatura,770,570); }
- else if (Temperatura > 9 && Temperatura < 100) { textFont(font,65); text(Temperatura,750,570); }
- else if (Temperatura > 99 && Temperatura < 140) { textFont(font,65); text(Temperatura,730,570); }
- //RPM
- /* Gear=Gear + 1;
- if (Gear > 7) {Gear = 1;}
- Brzina =Brzina + 3;
- if (Brzina > 260){Brzina = 1;}
- Ulje =Ulje + 1;
- if (Ulje > 1){Ulje = 0;}
- RPM =RPM + 40;
- if (RPM > 17999){RPM = 1;}
- Temperatura =Temperatura + 1;
- if (Temperatura > 138){Temperatura = 1;}
- */
- text(frameRate,20,50);
- }
- void serialEvent(Serial myPort) {
- String inString = myPort.readStringUntil(','); // read a byte from the serial port:
- String items[] = split(inString, ':'); // split the string into multiple strings// where there is a ":"
- if (items.length > 1) { // if there was more than one string after the split
- String label = trim(items[0]); // remove any whitespace from the label
- String val = split(items[1], ',')[0]; // remove the ',' off the end
- if (label.equals("Gear")) { // check what the label was and update the appropriate variable
- Gear = int(val); }
- if (label.equals("Brzina")) {
- Brzina = int(val); }
- if (label.equals("Ulje")) {
- Ulje = int(val); }
- if (label.equals("RPM")) {
- RPM = int(val); }
- if (label.equals("Temperatura")) {
- Temperatura = int(val); }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement