Advertisement
Guest User

Untitled

a guest
Oct 30th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.50 KB | None | 0 0
  1. // Importar biblioteca comunicacao serie
  2. import processing.serial.*;
  3.  
  4. // Criar objeto do tipo Serial chamado myPort
  5. Serial myPort;
  6.  
  7. // Definir variaveis que mudam as cores dos botoes
  8. int v01 = 150;
  9. int v01c = 150;
  10. int v02 = 150;
  11. int v02c = 150;
  12. int v03 = 150;
  13. int v03c = 150;
  14. int v04 = 150;
  15. int v04c = 150;
  16. int v05 = 150;
  17. int v05c = 150;
  18.  
  19. PImage img;
  20. void setup() {
  21.   // Abrir o porto de comunicação
  22.   myPort = new Serial(this, Serial.list()[0], 9600);
  23.  
  24.   // Criar uma janela com as dimensões 460x230 e preencher a preto
  25.   //size(460, 230);
  26.   size(900,712);
  27.   surface.setResizable(true);
  28.   img = loadImage("teste.png");
  29.  
  30.  
  31.   // Nome da interface a letras brancas no fundo da janela
  32.   textSize(24);
  33.   textAlign(CENTER);
  34.   fill(255, 255, 255);
  35.   text("Bruno M.", 230, 210);
  36.  // fullScreen();
  37. }
  38.  
  39. void draw() {
  40.   background(img);
  41.   // VAGA 01
  42.   fill(0, v01, 0);
  43.   rect(53, 0, 140, 220);
  44.   fill(255, 255, 255);
  45.   textSize(24);
  46.   textAlign(CENTER);
  47.   text("01", 90, 95);
  48.  
  49.   // VAGA 02
  50.   fill(v02, 0, 0);
  51.   rect(225, 0, 140, 220);
  52.   fill(255,255,255);
  53.   text("02", 250, 95);
  54.  
  55.   // VAGA 03
  56.   fill(0, v03, 0);
  57.   rect(395,0,140,220);
  58.   fill(255,255,255);
  59.   text("03",450,95);
  60.  
  61.   // VAGA 04
  62.   fill(0, v04, 0);
  63.   rect(560,0,140,220);
  64.   fill(255,255,255);
  65.   text("04",590,95);  
  66.  
  67.   // VAGA 05
  68.   fill(0,v04,0);
  69.   rect(730, 0, 140, 220);
  70.   fill(255,255,255);
  71.   text("05", 760, 95);
  72.  
  73.  
  74.   // Enviar informacao para o Arduino
  75.   // Premir botao verde
  76.   if (mousePressed && mouseX > 20 && mouseX < 160 && mouseY > 20 && mouseY < 160)
  77.   {
  78.     // Desligar LED verde
  79.     if (v01 == 255)
  80.     {
  81.       myPort.write("2");
  82.     }
  83.     // Ligar LED verde
  84.     else
  85.     {
  86.       myPort.write("1");
  87.     }
  88.   }
  89.  
  90.   // Premir botao vermelho
  91.   else if (mousePressed && mouseX > 160 && mouseX < 300 && mouseY > 20 && mouseY < 160)
  92.   {
  93.     // Desligar LED vermelho
  94.     if (v02 == 255 && v02c == 255)
  95.     {
  96.       myPort.write("4");
  97.     }
  98.     // Ligar LED vermelho
  99.     else
  100.     {
  101.       myPort.write("3");
  102.     }
  103.   }
  104.  
  105. }
  106.  
  107. void mouseClicked() {
  108.   // Botao verde
  109.   if (mouseX > 20 && mouseX < 160 && mouseY > 20 && mouseY < 160)
  110.   {
  111.     if (v01 == 150)
  112.     {
  113.       v01c = 255;
  114.     }
  115.  
  116.     else
  117.     {
  118.       v01 = 150;
  119.     }
  120.   }
  121.  
  122.   // Botao vermelho
  123.   if (mouseX > 160 && mouseX < 300 && mouseY > 20 && mouseY < 160)
  124.   {
  125.     if (v02 == 150 && v02 == 150)
  126.     {
  127.       v02c = 255;
  128.       v02c = 255;
  129.     }
  130.  
  131.     else
  132.     {
  133.       v01 = 150;
  134.       v01 = 150;
  135.     }
  136.   }
  137.  
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement