Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Laboratorio 6
- Crhistian David Lucumi
- */
- import controlP5.*;
- import processing.serial.*;
- ControlP5 cp5;
- CheckBox checkbox;
- int[] colores = { 0, 0, 0 };
- int[] binar = { 128, 64, 32, 16, 8, 4, 2, 1 };
- Serial serial;
- void setup() {
- size(700, 400);
- smooth();
- cp5 = new ControlP5(this);
- checkbox = cp5.addCheckBox("checkBox")
- .setPosition(100, 200)
- .setColorForeground(color(120))
- .setColorActive(color(255))
- .setColorLabel(color(255))
- .setSize(40, 40)
- .setItemsPerRow(4)
- .setSpacingColumn(30)
- .setSpacingRow(20)
- .addItem("LED 1", 1)
- .addItem("LED 2", 2)
- .addItem("LED 3", 3)
- .addItem("LED 4", 4)
- .addItem("LED 5", 5)
- .addItem("LED 6", 6)
- .addItem("LED 7", 7)
- .addItem("LED 8", 8);
- cp5.addButton("Encender")
- .setPosition(100, 320)
- .setSize(80, 40);
- serial = new Serial(this, Serial.list()[0], 9600);
- }
- void draw() {
- background(0);
- pushMatrix();
- translate(width / 2 + 200, height / 2);
- stroke(255);
- strokeWeight(2);
- fill(colores[0], colores[1], colores[2]);
- ellipse(0, 0, 200, 200);
- popMatrix();
- }
- void controlEvent(ControlEvent theEvent) {
- if (theEvent.isFrom(checkbox)) {
- } else if (theEvent.getController().getName().equals("Encender")) {
- colores[0] = 0;
- colores[1] = 0;
- colores[2] = 0;
- int total = 0;
- for (int i = 0; i < checkbox.getArrayValue().length; i++) {
- int n = (int)checkbox.getArrayValue()[i];
- if (n > 0) {
- total += binar[i];
- }
- }
- serial.write("" + total);
- if (total == 224) {
- colores[0] = 255;
- colores[1] = 255;
- colores[2] = 0;
- }
- if (total == 28) {
- colores[0] = 0;
- colores[1] = 255;
- colores[2] = 0;
- }
- if (total == 3) {
- colores[0] = 255;
- colores[1] = 0;
- colores[2] = 0;
- }
- println(total);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement