import processing.serial.*;
import controlP5.*;
ControlP5 cp5;
Serial puerto;
int LED;
boolean isEvent;
int colorBackground = 100;
void setup() {
size(700,200);
noStroke();
cp5 = new ControlP5(this); //ControlP5 es una interfaz gráfica
cp5.addSlider("LED")
.setPosition(50,50)
.setWidth(600)
.setHeight(30)
.setRange(7,2)
.setValue(3)
.setNumberOfTickMarks(6)
.setSliderMode(Slider.FLEXIBLE);
//En el arduino solo se maneja
//un puerto, por ello la posicion es "0"
String COM = Serial.list()[0];
puerto = new Serial(this, COM, 9600);
}
//draw es identico al loop en arduino
void draw() {
background(colorBackground);
//Se ilumina el led correspondiente en cada evento
//del Slider
if(isEvent){
puerto.write(LED);
isEvent = false;
}
}
//se capura el evento de control
void controlEvent(ControlEvent e){
isEvent = true;
}