// Lab 6
// Cristian Córdoba
// Universidad Santiago de Cali
// Versión 1.0 Processing
import controlP5.*;
import processing.serial.*;
// Se definen los objetos usados.
ControlP5 cp5;
Serial serial;
// Variables.
int myColor = color(255);
int c1, c2;
String Lectura;
int [] Clr = {
255, 255, 255
};
float n, n1;
// Solamente se ejecuta una vez, al iniciar el Sketch.
void setup() {
size(200, 350); // Tamaño de la ventana.
noStroke(); // No dibujar el border de los rectángulos.
// Crear el objeto ControlP5 y cada boton.
cp5 = new ControlP5(this);
cp5.addButton("Sec0")
.setValue(0)
.setPosition(50, 50)
.setSize(100, 25)
;
cp5.addButton("Sec1")
.setValue(100)
.setPosition(50, 80)
.setSize(100, 25)
;
cp5.addButton("Sec2")
.setValue(0)
.setPosition(50, 110)
.setSize(100, 25)
;
cp5.addButton("Sec3")
.setValue(0)
.setPosition(50, 140)
.setSize(100, 25)
;
cp5.addButton("Sec4")
.setValue(0)
.setPosition(50, 170)
.setSize(100, 25)
;
cp5.addButton("Sec5")
.setValue(0)
.setPosition(50, 200)
.setSize(100, 25)
;
cp5.addButton("Sec6")
.setValue(0)
.setPosition(50, 230)
.setSize(100, 25)
;
cp5.addButton("Sec7")
.setValue(0)
.setPosition(50, 260)
.setSize(100, 25)
;
// Creamos el objeto del puerto Serial.
serial = new Serial(this, Serial.list()[1], 9600);
}
void draw() {
// Se dibuja el color de fondo de acuerdo
// al boton pulsado.
background(myColor);
myColor = lerpColor(c1, c2, n);
n += (1-n)* 0.05;
}
public void controlEvent(ControlEvent evento) {
// Guardar el nombre y valor del evento.
n = 0;
String nombre = evento.getController().getName();
// Dependiendo del nombre del evento se carga una letra a
// la variable del mismo nombre y se guarda un color para cada uno.
if (nombre == "Sec0") {
Lectura = "0";
Clr[0] = 200;
Clr[1] = 250;
Clr[2] = 255;
}
if (nombre == "Sec1") {
Lectura = "1";
Clr[0] = 21;
Clr[1] = 156;
Clr[2] = 255;
}
if (nombre == "Sec2") {
Lectura = "2";
Clr[0] = 236;
Clr[1] = 0;
Clr[2] = 21;
}
if (nombre == "Sec3") {
Lectura = "3";
Clr[0] = 1;
Clr[1] = 56;
Clr[2] = 100;
}
if (nombre == "Sec4") {
Lectura = "4";
Clr[0] = 100;
Clr[1] = 50;
Clr[2] = 200;
}
if (nombre == "Sec5") {
Lectura = "5";
Clr[0] = 25;
Clr[1] = 225;
Clr[2] = 150;
}
if (nombre == "Sec6") {
Lectura = "6";
Clr[0] = 230;
Clr[1] = 200;
Clr[2] = 200;
}
if (nombre == "Sec7") {
Lectura = "7";
Clr[0] = 100;
Clr[1] = 100;
Clr[2] = 100;
}
c1 = c2;
c2 = color(Clr[0], Clr[1], Clr[2]);
println(Lectura);
serial.write(Lectura);
}