Advertisement
CrhisDLM

Lab 6 Processing

Jul 7th, 2025
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 KB | None | 0 0
  1. /*
  2. Laboratorio 6
  3. Crhistian David Lucumi
  4. */
  5.  
  6. import controlP5.*;
  7. import processing.serial.*;
  8. ControlP5 cp5;
  9.  
  10. CheckBox checkbox;
  11. int[] colores = { 0, 0, 0 };
  12. int[] binar = { 128, 64, 32, 16, 8, 4, 2, 1 };
  13. Serial serial;
  14. void setup() {
  15.   size(700, 400);
  16.   smooth();
  17.   cp5 = new ControlP5(this);
  18.   checkbox = cp5.addCheckBox("checkBox")
  19.                .setPosition(100, 200)
  20.                .setColorForeground(color(120))
  21.                .setColorActive(color(255))
  22.                .setColorLabel(color(255))
  23.                .setSize(40, 40)
  24.                .setItemsPerRow(4)
  25.                .setSpacingColumn(30)
  26.                .setSpacingRow(20)
  27.                .addItem("LED 1", 1)
  28.                .addItem("LED 2", 2)
  29.                .addItem("LED 3", 3)
  30.                .addItem("LED 4", 4)
  31.                .addItem("LED 5", 5)
  32.                .addItem("LED 6", 6)
  33.                .addItem("LED 7", 7)
  34.                .addItem("LED 8", 8);
  35.  
  36.   cp5.addButton("Encender")
  37.     .setPosition(100, 320)
  38.     .setSize(80, 40);
  39.   serial = new Serial(this, Serial.list()[0], 9600);
  40. }
  41. void draw() {
  42.   background(0);
  43.   pushMatrix();
  44.   translate(width / 2 + 200, height / 2);
  45.   stroke(255);
  46.   strokeWeight(2);
  47.   fill(colores[0], colores[1], colores[2]);
  48.   ellipse(0, 0, 200, 200);
  49.   popMatrix();
  50. }
  51.  
  52. void controlEvent(ControlEvent theEvent) {
  53.   if (theEvent.isFrom(checkbox)) {
  54.  
  55.   } else if (theEvent.getController().getName().equals("Encender")) {
  56.     colores[0] = 0;
  57.     colores[1] = 0;
  58.     colores[2] = 0;
  59.     int total = 0;
  60.     for (int i = 0; i < checkbox.getArrayValue().length; i++) {
  61.       int n = (int)checkbox.getArrayValue()[i];
  62.       if (n > 0) {
  63.         total += binar[i];
  64.       }
  65.     }
  66.     serial.write("" + total);
  67.     if (total == 224) {
  68.       colores[0] = 255;
  69.       colores[1] = 255;
  70.       colores[2] = 0;
  71.     }
  72.     if (total == 28) {
  73.       colores[0] = 0;
  74.       colores[1] = 255;
  75.       colores[2] = 0;
  76.     }
  77.     if (total == 3) {
  78.       colores[0] = 255;
  79.       colores[1] = 0;
  80.       colores[2] = 0;
  81.     }
  82.     println(total);
  83.   }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement