Advertisement
UrQuan

Untitled

Jun 9th, 2015
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. import processing.serial.*;
  2. Serial myPort;
  3. PImage img1;
  4. PImage img2;
  5. PImage img3;
  6. PFont font;
  7. int Gear= 0;
  8. int Brzina =0;
  9. int Ulje =1;
  10. int RPM =0;
  11. int Temperatura =0;
  12. int t=255;
  13.  
  14. void setup() {
  15. size(1280, 720,P2D);
  16. img1 = loadImage("1.png");
  17. img2 = loadImage("2.png");
  18. img3 = loadImage("3.png");
  19. frameRate(100);
  20. myPort = new Serial(this, "COM10", 9600); //Prepoznavanje ulaznih bitova
  21. font = loadFont("Open24DisplaySt-48.vlw");
  22. myPort.bufferUntil(',');
  23. }
  24.  
  25.  
  26. void draw() {
  27.  
  28.  
  29. image(img2,0,0);
  30.  
  31.  
  32. //RPM
  33.  
  34. if (RPM <= 7000 ){fill(RPM/27.46,255,0); stroke(RPM/27.46,255,0);}
  35. else if (RPM > 7000){fill(255,417.32-RPM/43.13,0); stroke(255,417.32-RPM/43.13,0);}
  36. float c = map(RPM,0,7000,89,270);
  37. if (RPM <= 7000){ arc(230, 374, 437, 437, radians(89),radians(c), CENTER); }
  38. else if (RPM > 5000){
  39. arc(230, 374, 437, 437, radians(89),radians(270), CENTER);}
  40.  
  41.  
  42. float j = map(RPM,7001,18000,1,720);
  43. if (RPM < 18001 && RPM > 7000){
  44. rect(229,148, j, 95); }
  45. else if (RPM > 17999){rect(229,148, 617, 95);}
  46. image(img3,0,0);
  47.  
  48.  
  49. //Brzina
  50. //fill(#922528);
  51. //stroke(#922528);
  52.  
  53. float a = map(Brzina,20,260,133,406);
  54. fill(203,62-Brzina/4.1935,62-Brzina/4.1935);
  55. stroke(203,62-Brzina/4.1935,62-Brzina/4.1935);
  56. arc(1042, 367, 444, 444, radians(133),radians(a), CENTER);
  57.  
  58.  
  59. //Ulje
  60. t=t-15;
  61. if (t<15){t=255;}
  62. if (Ulje == 1){ fill(255,t,t); ellipse(790, 290, 55, 55); }
  63. else if (Ulje == 0){ fill(#FFFFFF); ellipse(790, 290, 55, 55);}
  64. fill(#FFFFFF);
  65.  
  66.  
  67. image(img1,0,0);
  68.  
  69. if (RPM < 10) { textFont(font,80);text(RPM,227,400); } //Brzina
  70. else if (RPM > 9 && RPM < 100) { textFont(font,80);text(RPM,207,400); }
  71. else if (RPM > 99 && RPM < 1000) { textFont(font,80);text(RPM,195,400); }
  72. else if (RPM > 999 && RPM < 10000) { textFont(font,80);text(RPM,175,400); }
  73. else if (RPM > 9999 && RPM < 18001) { textFont(font,80);text(RPM,155,400); }
  74.  
  75. if (Gear >= 1 && Gear <= 6) { textFont(font,160); text(Gear,1013,428); }
  76. else if (Gear == 7) { textFont(font,160); text("N",1011,428); }
  77.  
  78. if (Brzina > 0 && Brzina < 10) { textFont(font,65);text(Brzina,320,570); } //Brzina
  79. else if (Brzina > 9 && Brzina < 100) { textFont(font,65);text(Brzina,300,570); }
  80. else if (Brzina > 99 && Brzina < 300) { textFont(font,65);text(Brzina,280,570); }
  81.  
  82. if (Temperatura > 0 && Temperatura < 10) { textFont(font,65); text(Temperatura,770,570); }
  83. else if (Temperatura > 9 && Temperatura < 100) { textFont(font,65); text(Temperatura,750,570); }
  84. else if (Temperatura > 99 && Temperatura < 140) { textFont(font,65); text(Temperatura,730,570); }
  85. //RPM
  86.  
  87. /* Gear=Gear + 1;
  88. if (Gear > 7) {Gear = 1;}
  89. Brzina =Brzina + 3;
  90. if (Brzina > 260){Brzina = 1;}
  91. Ulje =Ulje + 1;
  92. if (Ulje > 1){Ulje = 0;}
  93. RPM =RPM + 40;
  94. if (RPM > 17999){RPM = 1;}
  95. Temperatura =Temperatura + 1;
  96. if (Temperatura > 138){Temperatura = 1;}
  97. */
  98. text(frameRate,20,50);
  99.  
  100. }
  101.  
  102. void serialEvent(Serial myPort) {
  103. String inString = myPort.readStringUntil(','); // read a byte from the serial port:
  104. String items[] = split(inString, ':'); // split the string into multiple strings// where there is a ":"
  105. if (items.length > 1) { // if there was more than one string after the split
  106. String label = trim(items[0]); // remove any whitespace from the label
  107. String val = split(items[1], ',')[0]; // remove the ',' off the end
  108. if (label.equals("Gear")) { // check what the label was and update the appropriate variable
  109. Gear = int(val); }
  110. if (label.equals("Brzina")) {
  111. Brzina = int(val); }
  112. if (label.equals("Ulje")) {
  113. Ulje = int(val); }
  114. if (label.equals("RPM")) {
  115. RPM = int(val); }
  116. if (label.equals("Temperatura")) {
  117. Temperatura = int(val); }
  118.  
  119.  
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement