Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import processing.serial.*;
  2. import controlP5.*;
  3.  
  4. ControlP5 cp5;
  5. Serial puerto;
  6. int LED;
  7. boolean isEvent;
  8. int colorBackground = 100;
  9.  
  10. void setup() {
  11.   size(700,200);
  12.   noStroke();
  13.  
  14.   cp5 = new ControlP5(this); //ControlP5 es una interfaz gráfica
  15.   cp5.addSlider("LED")
  16.      .setPosition(50,50)
  17.      .setWidth(600)
  18.      .setHeight(30)
  19.      .setRange(7,2)
  20.      .setValue(3)
  21.      .setNumberOfTickMarks(6)
  22.      .setSliderMode(Slider.FLEXIBLE);
  23.  
  24.   //En el arduino solo se maneja
  25.   //un puerto, por ello la posicion es "0"
  26.   String COM = Serial.list()[0];
  27.   puerto = new Serial(this, COM, 9600);
  28. }
  29.  
  30. //draw es identico al loop en arduino
  31. void draw() {
  32.   background(colorBackground);  
  33.  
  34.   //Se ilumina el led correspondiente en cada evento
  35.   //del Slider  
  36.   if(isEvent){
  37.     puerto.write(LED);  
  38.     isEvent = false;  
  39.   }
  40. }
  41.  
  42. //se capura el evento de control
  43. void controlEvent(ControlEvent e){
  44.   isEvent = true;
  45. }