/* Crhistian David Lucumi Laboratorio 7 */ import controlP5.*; import processing.serial.*; ControlP5 cp5; CheckBox checkbox; PImage img; 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(5) .setSpacingColumn(30) .setSpacingRow(20) .addItem("0", 63) .addItem("1", 6) .addItem("2", 91) .addItem("3", 79) .addItem("4", 102) .addItem("5", 109) .addItem("6", 125) .addItem("7", 7) .addItem("8", 127) .addItem("9", 111); serial = new Serial(this, Serial.list()[0], 9600); img = loadImage("0.png"); } void draw() { background(0); pushMatrix(); translate(width / 2 + 200, height / 2); stroke(255); strokeWeight(2); popMatrix(); image(img, 490, 100, 200, 200); } void controlEvent(ControlEvent theEvent) { if (theEvent.isFrom(checkbox)) { print("got an event from " + checkbox.getName() + "\t\n"); // checkbox uses arrayValue to store the state of // individual checkbox-items. usage: int col = 0; for (int i = 0; i < checkbox.getArrayValue().length; i++) { int n = (int)checkbox.getArrayValue()[i]; if (n == 1) { //myColorBackground += checkbox.getItem(i).internalValue(); int num = (int)checkbox.getItem(i).internalValue(); serial.write("" + num); img = loadImage(checkbox.getItem(i).getName() + ".png"); } } println(); } }