Advertisement
Guest User

LAB 3 PRO

a guest
Sep 2nd, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.58 KB | None | 0 0
  1. // Se utiliza las librerias ControlP5 y Serial del Processing
  2. import controlP5.*;
  3. import processing.serial.*;
  4.  
  5. // Se define la variable cP5 del tipo ControlP5
  6. ControlP5 cP5;
  7.  
  8. // Se le da nombres a los dos Slider y al Serial
  9. Slider SliON;
  10. Slider SliOFF;
  11. Serial serial;
  12.  
  13. // ConfiguraciĆ³n inicial
  14. void setup() {
  15.   size(610, 400);  //TamaƱo de la ventana
  16.  
  17.   cP5 = new ControlP5(this);  //Crea el objeto ControlP5
  18.  
  19.   // Crea el Slider del Tiempo Encendido
  20.   SliON = cP5.addSlider("O")
  21.     .setRange(0, 1000)
  22.       .setValue(100)
  23.         .setPosition(60, 150)
  24.           .setSize(300, 30)
  25.             .setNumberOfTickMarks(20)
  26.               .setLabelVisible(false)
  27.                 .setColorForeground(color(255, 0, 0))
  28.                   .setColorBackground(color(0))
  29.                     .setColorActive(color(255, 255, 0))
  30.                       ;
  31.   // Crea el Slider del Tiempo Apagado
  32.   SliOFF = cP5.addSlider("F")
  33.     .setRange(0, 1000)
  34.       .setValue(100)
  35.         .setPosition(60, 250)
  36.           .setSize(300, 30)
  37.             .setNumberOfTickMarks(20)
  38.               .setLabelVisible(false)
  39.                 .setColorForeground(color(255, 0, 0))
  40.                   .setColorBackground(color(0))
  41.                     .setColorActive(color(255, 255, 0))
  42.                       ;
  43.   String puerto = Serial.list()[1];
  44.   serial = new Serial(this, puerto, 9600);
  45. }
  46.  
  47. // Se dibuja cada frame
  48. void draw() {
  49.   background(0xFF444444);  //Color Gris del fondo
  50.  
  51.   fill(10);
  52.   rect(35, 125, 380, 100);
  53.   fill(0, 225, 0);
  54.   rect(45, 135, 360, 80);
  55.   fill(10);
  56.   rect(35, 225, 380, 100);
  57.   fill(0, 225, 0);
  58.   rect(45, 235, 360, 80);
  59.   fill(50, 255, 255);
  60.   textFont(createFont("Gill Sans Ultra Bold", 50));
  61.   text("TIEMPO DE:", 130, 100);
  62.   fill(50, 255, 255);
  63.   textSize(20);
  64.   text("ENCENDIDO", 420, 170);
  65.   fill(50, 255, 255);
  66.   textSize(20);
  67.   text("APAGADO", 420, 270);
  68.   fill(0, 0, 0);
  69.   textSize(20);
  70.   text("(OFF)", 460, 300);
  71.   fill(0, 225, 0);
  72.   textSize(20);
  73.   text("(0N)", 460, 200);
  74.   fill(225, 0, 0);
  75.   textSize(15);
  76.   text("0", 55, 200);
  77.   fill(255, 0, 0);
  78.   textSize(15);
  79.   text("1000", 330, 200);
  80.   fill(255, 0, 0);
  81.   textSize(15);
  82.   text("0", 55, 300);
  83.   fill(255, 0, 0);
  84.   textSize(15);
  85.   text("1000", 330, 300);
  86.   fill(0, 225, 0);
  87.   textSize(25);
  88.   text("LUIS MIGUEL TORRES ARTUNDUAGA", 10, 370);
  89. }
  90.  
  91. // Como se va actuar cuando ocurra un evento con los Slider
  92. void controlEvent(ControlEvent evento) {
  93.   String nombre = evento.getController().getName();
  94.   int valor = int(evento.getController().getValue());
  95.   serial.write(nombre + valor);
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement