/********** Proyecto **********
* Laboratorio 06: El laboratorio consiste en Controlar 8 LEDs
* desde el Arduino, a través de un IC 74HC595,
* definiendo mínimo 8 patrones de movimiento que son
* controlados desde una interfaz gráfica en Processing/ControlP5.
* Autor: Oscar E. Bustamante R.
* Version: 1
*/
import controlP5.*;
import processing.serial.*;
ControlP5 cp5;
int colorDeFondo = color (213, 213, 213);
int val; // Data received from the serial port
RadioButton radioButton;
Serial serial; // definir la variable serial del tipo Serial
int lf = 10; // ASCII linefeed
void setup() {
size(400, 300);
noStroke();
// Print a list of the serial ports, for debugging purposes:
println("Puertos usados:");
printArray(Serial.list());
cp5 = new ControlP5(this);
radioButton = cp5.addRadioButton("radioButton")
.setPosition(20, 50)
.setSize(40, 20)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(0))
.setItemsPerRow(4)
.setSpacingColumn(50)
.setSpacingRow(20)
.addItem("Patron 1", 1)
.addItem("Patron 2", 2)
.addItem("Patron 3", 3)
.addItem("Patron 4", 4)
.addItem("Patron 5", 5)
.addItem("Patron 6", 6)
.addItem("Patron 7", 7)
.addItem("Patron 8", 8)
;
for (Toggle t : radioButton.getItems ()) {
//t.captionLabel().setColorBackground(color(255,80));
t.captionLabel().style().moveMargin(-7, 0, 0, -3);
t.captionLabel().style().movePadding(7, 0, 0, 3);
t.captionLabel().style().backgroundWidth = 45;
t.captionLabel().style().backgroundHeight = 13;
}
/*
cp5.addButton("Enviar")
.setPosition(100, 320)
.setSize(80,40)
;
*/
serial = new Serial(this, Serial.list()[2], 9600);
serial.bufferUntil(lf);
}
void draw() {
background(colorDeFondo);
}
//Majejando los radioButtons con el teclado
void keyPressed() {
switch(key) {
case('0'):
radioButton.deactivateAll();
break;
case('1'):
radioButton.activate(0);
break;
case('2'):
radioButton.activate(1);
break;
case('3'):
radioButton.activate(2);
break;
case('4'):
radioButton.activate(3);
break;
case('5'):
radioButton.activate(4);
break;
case('6'):
radioButton.activate(5);
break;
case('7'):
radioButton.activate(6);
break;
case('8'):
radioButton.activate(7);
break;
}
}
void controlEvent(ControlEvent evento) {
if (evento.isFrom(radioButton)) {
int total = 0;
total = (int)evento.getValue();
println("\nValor a ser enviado por Serial = " + total);
//serial.write(total+"");
serial.write("P"+total);
}
//println(serial.readString());
}