import processing.serial.*; int lf = 10; // Linefeed in ASCII int value; String myString = null; Serial myPort; // The serial port Button button; void setup(){ size(800,600); background(0); button = new Button(300, 300, " START "); // List all the available serial ports println(Serial.list()); // I know that the first port in the serial list on my mac // is always my Keyspan adaptor, so I open Serial.list()[0]. // Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[0], 9600); myPort.clear(); // Throw out the first reading, in case we started reading // in the middle of a string from the sender. myString = myPort.readStringUntil(lf); myString = null; } void draw(){ while (myPort.available() > 0) { myString = myPort.readStringUntil(lf); if (myString != null) { myString = trim(myString); value = int(myString); println(value); } } background(150); button.draw(); textSize(25); text(value, 60, 120); //Here's the text call. text("Turns:",60, 60); //Here's the text call. } void mousePressed(){ if(button.over()){ myPort.write('0'); } } class Button{ int x,y; String label; Button(int x, int y, String label){ this.x = x; this.y = y; this.label = label; } void draw(){ fill(200); if(over()){ fill(255); } rect(x, y, textWidth(label), 25); fill(0); text(label, x, y + 20); } boolean over(){ if(mouseX >= x && mouseY >= y && mouseX <= x + textWidth(label) && mouseY <= y + 22){ return true; } return false; } }