import processing.serial.*; Serial port; boolean ledOn = false; int counter = 0; PFont font; void setup() { size(500, 300); //printArray(Serial.list()); port = new Serial(this, Serial.list()[0], 9600); font = createFont("Arial", 100); } void draw() { background(190); if (mousePressed && !ledOn) { port.write("on\n"); ledOn = true; counter++; } else if (!mousePressed && ledOn) { port.write("off\n"); ledOn = false; } if (ledOn) { fill(230, 0, 0, 200); } else { fill(255, 0, 0, 80); } stroke(50); arc(150, 80, 70, 70, -PI, 0); noStroke(); rect(115, 80, 70, 50); stroke(50); line(115, 80, 115, 130); line(185, 80, 185, 130); rect(100, 130, 100, 20); fill(127); rect(130, 150, 10, 100); rect(160, 150, 10, 80); if (port.available() > 0) { String command = port.readStringUntil('\n'); if (command != null && trim(command).equals("on")) { counter = 0; } } fill(0); textFont(font); textAlign(CENTER); text(counter, 350, 180); }