import controlP5.*;
import processing.serial.*;
ControlP5 cp5;
Slider slider1;
Slider slider2;
Serial serial;
Textlabel texto1, texto2, texto3, texto4;
Textlabel texto5, texto6;
void setup()
{
serial = new Serial(this, Serial.list()[0],9600);
String puerto = Serial.list()[0];
size(750,330);
cp5 = new ControlP5(this);
slider1 = cp5.addSlider("O",0,1000,500,40,150,300,40);
slider1.setColor(new CColor(0xFF00FF00,0xFF555555,0xFF009F00,0xFFFFFFFF,0xFFFFFFFF));
slider1.setLabelVisible(false);
slider2 = cp5.addSlider("F",0,1000,500,400,150,300,40);
slider2.setColor(new CColor(0xFF00FF00,0xFF555555,0xFF009F00,0xFFFFFFFF,0xFFFFFFFF));
slider2.setLabelVisible(false);
texto1 = cp5.addTextlabel("label")
.setText("CONTROL DE LEDS")
.setPosition(210,50)
.setColorValue(0xffff0000)
.setFont(createFont("Comic Sans MS",30))
;
texto2 = cp5.addTextlabel("label1")
.setText("TIEMPO ENCENDIDO (ms)")
.setPosition(90,120)
.setColorValue(0xffff0000)
.setFont(createFont("Comic Sans MS",15))
;
texto3 = cp5.addTextlabel("label2")
.setText("TIEMPO APAGADO (ms)")
.setPosition(460,120)
.setColorValue(0xffff0000)
.setFont(createFont("Comic Sans MS",15))
;
texto4 = new Textlabel(cp5,"Juberth Andres Reneria ",40,230,600,200);
texto4.setFont(createFont("MV Boli",15));
texto5 = new Textlabel(cp5,"Ingenieria Electronica",40,250,600,200);
texto5.setFont(createFont("MV Boli",15));
texto6 = new Textlabel(cp5,"Noveno semestre",40,270,600,200);
texto6.setFont(createFont("MV Boli",15));
}
void draw()
{
background(50,30,100);
texto4.draw(this);
texto5.draw(this);
texto6.draw(this);
}
void controlEvent (ControlEvent evento)
String nombre = evento.getController().getName();
int valor = int(evento.getController().getValue());
serial.write(nombre + ":" + valor);
println(nombre + ":" + valor);
}
for (int i=0;i<maxleds;i++)
pinMode(led[i],OUTPUT);
}
void loop()
{
for (int i=0;i<=maxleds;i++)
{
if (Serial.available()>0)
{
valor = Serial.read();
if (valor == 'O')
t1 = Serial.parseInt();
if (valor == 'F')
t2 = Serial.parseInt();
}
prender(led[i],t1);
apagar(led[i],t2);
}
for (int i=maxleds;i>=0;i--)
{
if (Serial.available()>0)
{
valor = Serial.read();
if (valor == 'O')
t1 = Serial.parseInt();
if (valor == 'F')
t2 = Serial.parseInt();
}
prender(led[i],t1);
apagar(led[i],t2);
}
}
void prender(int i, int t)
{
digitalWrite(i, HIGH);
delay(t);
}
void apagar(int i, int t)
{
digitalWrite(i, LOW);
delay(t);
}