Advertisement
CrhisDLM

Lab 7 Processing

Jul 7th, 2025 (edited)
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. /*
  2. Crhistian David Lucumi
  3. Laboratorio 7
  4. */
  5. import controlP5.*;
  6. import processing.serial.*;
  7. ControlP5 cp5;
  8.  
  9. CheckBox checkbox;
  10. PImage img;
  11. Serial serial;
  12. void setup() {
  13.   size(700, 400);
  14.   smooth();
  15.   cp5 = new ControlP5(this);
  16.   checkbox = cp5.addCheckBox("checkBox")
  17.                .setPosition(100, 200)
  18.                .setColorForeground(color(120))
  19.                .setColorActive(color(255))
  20.                .setColorLabel(color(255))
  21.                .setSize(40, 40)
  22.                .setItemsPerRow(5)
  23.                .setSpacingColumn(30)
  24.                .setSpacingRow(20)
  25.                .addItem("0", 63)
  26.                .addItem("1", 6)
  27.                .addItem("2", 91)
  28.                .addItem("3", 79)
  29.                .addItem("4", 102)
  30.                .addItem("5", 109)
  31.                .addItem("6", 125)
  32.                .addItem("7", 7)
  33.                .addItem("8", 127)
  34.                .addItem("9", 111);
  35.   serial = new Serial(this, Serial.list()[0], 9600);
  36.   img = loadImage("0.png");
  37. }
  38. void draw() {
  39.   background(0);
  40.   pushMatrix();
  41.   translate(width / 2 + 200, height / 2);
  42.   stroke(255);
  43.   strokeWeight(2);
  44.   popMatrix();
  45.   image(img, 490, 100, 200, 200);
  46. }
  47. void controlEvent(ControlEvent theEvent) {
  48.   if (theEvent.isFrom(checkbox)) {
  49.  
  50.     print("got an event from " + checkbox.getName() + "\t\n");
  51.     // checkbox uses arrayValue to store the state of
  52.     // individual checkbox-items. usage:
  53.     int col = 0;
  54.     for (int i = 0; i < checkbox.getArrayValue().length; i++) {
  55.       int n = (int)checkbox.getArrayValue()[i];
  56.  
  57.       if (n == 1) {
  58.         //myColorBackground += checkbox.getItem(i).internalValue();
  59.         int num = (int)checkbox.getItem(i).internalValue();
  60.         serial.write("" + num);
  61.  
  62.         img = loadImage(checkbox.getItem(i).getName() + ".png");
  63.       }
  64.     }
  65.     println();
  66.   }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement