The reason the image only shows the last thing in the draw() loop is that Processing doesn’t draw anything until it exits the draw() loop.

There is no const declaration. Use final instead. Apparently this is a Java thing. int const in Arduino becomes final int in Processing

 

Basics: Flash the background of the display window:

final int DISPLAY_TIME_A = 1000;
final int DISPLAY_TIME_B = DISPLAY_TIME_A * 2;
int lastTime;

void setup()
{
size(200, 200);
background(120);
lastTime = millis();
}

void draw()
{
if (millis() – lastTime > DISPLAY_TIME_A)
{
background(100);
}
if (millis() – lastTime > DISPLAY_TIME_B)
{
background(120);
lastTime = millis();
}
}

 

Basics: Make a square and flash it:

 

final int DISPLAY_TIME_A = 1000;
final int DISPLAY_TIME_B = DISPLAY_TIME_A * 2;
int lastTime;

void setup()
{
size(600, 600);
background(120);
lastTime = millis();
}

void draw()
{
if (millis() – lastTime > DISPLAY_TIME_A)
{
fill(127);
rect(250, 250, 100, 50);
}
if (millis() – lastTime > DISPLAY_TIME_B)
{
fill(40);
rect(250, 250, 100, 50);
lastTime = millis();
}
}

Alright. Can I get an input from an Arduino to change the background color?

https://playground.arduino.cc/Interfacing/Processing

“Run Arduino, open the Examples > Firmata > StandardFirmata, and upload it to the Arduino board.”

So far so good.

“Configure Processing for Serial” https://processing.org/reference/libraries/serial/

Umm. No. That’s not a tutorial, it’s a reference page.

 

So, to load the Serial library in Processing, use import processing.serial.*;

Gah. How do we find the port?

 

Run this code: Read the list in the text window in processing, and change the [n] number to select the /dev/cu.usbmodem**** on the list.

import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
int ledPin = 13;

void setup()
{
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[1], 57600);
arduino.pinMode(ledPin, Arduino.OUTPUT);
}

void draw()
{
arduino.digitalWrite(ledPin, Arduino.HIGH);
delay(500);
arduino.digitalWrite(ledPin, Arduino.LOW);
delay(1000);
}

firmata_example_output.pde

all of this Arduino arduino nonsense is confusing, but since it actually works, who am I to argue?

Now let’s try taking some input.

YES!

import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
int inputPin = 8;

void setup()
{
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[1], 57600);
arduino.pinMode(inputPin, Arduino.INPUT_PULLUP);
}

void draw()
{
int reading = arduino.digitalRead(inputPin);
if (reading > 0) {
background(255);
} else {
background(0);
}
}

firmata_example_input.pde