THE FOLLOWING CODE IS WRITTEN ON PROCESSING. I NEED THE CODE TO CHANGE THE COLOR OF A RECTANGLE WHEN THE VARIABLE B CHANGES ITS VALUE. WHEN D>20 THE RECTANGLE SHOULD BE GREEN, WHEN 20>D>10 IT SHOULD BE YELLOW, AND WHEN D<10 SHOULD BE RED. SO FAR I ONLY GET RED. THANKS FOR YOUR HELP
import processing.serial.*;
Serial port;
void setup() {
port = new Serial(this, "/dev/cu.usbserial-DN02SMXZ", 9600);
fullScreen();
}
void draw() {
background(50);
if (port.available() >
0) {
String a = port.readStringUntil(10);
if (a != null) {
text(a, 80, 80);
a = trim(a);
int b = int(a);
if (b >
20)
{
fill(0, 255, 0);
rect(b*2, 100, 100, 300);
delay(500);
} else if (b>
10)
{
fill(255, 155, 0);
rect(b*2, 100, 100, 300);
delay(500);
} else if (b <
10)
{
fill(255, 0, 0);
rect(b*2, 100, 100, 300);
delay(500);
}
}
}
}