import processing.serial.*;

Serial port; // Create object from Serial class
int count; // Data received from the serial port
PFont f;
PFont g;
float time;
float wait=1000;
boolean overBox=false;

void setup() {
size(640, 360);
background(0);

// Create the font
// printArray(PFont.list());
f = createFont("Georgia", 24);
g = createFont("Georgia", 70);
textAlign(CENTER, CENTER);
time=millis();
rectMode(RADIUS);

//println(Serial.list());
port = new Serial(this, Serial.list()[0], 9600);
}

void draw() {
if (0 < port.available()) { // If data is available to read,
count = port.read(); // read it and store it in val
}
background(0);
textFont(f);
text("The count is:",320,100);
rect(320,300,40,20);
fill(0);
text("RESET",320,300);
fill(255);
textFont(g);
text(count,320,150);
if (mouseX > 320-40 && mouseX < 320+40 &&
mouseY > 300-20 && mouseY < 300+20) {
overBox = true;
stroke(255, 204, 0);
fill(144);
rect(320,300,40,20);
fill(0);
textFont(f);
text("RESET",320,300);
textFont(g);
fill(255);
} else {
stroke(153);
overBox = false;
}

port.write(count);
}

void mousePressed() {
if(overBox) {
count = 0;
port.write(count);
}
}