Using the following Processing sketch with a photoresistor connected to an Arduino board :
import processing.serial.*;
Serial port;
float brightness;
void setup() {
size(1000, 1000); // Set the window size
port = new Serial(this, "COM4", 9600); // Initialize the serial port
port.bufferUntil('\n'); // Read until a newline character is received
}
void draw() {
background(255, 0, brightness); // Update the window background color
}
void serialEvent(Serial get) {
String inString = get.readStringUntil('\n'); // Read the incoming value as a string
if (inString != null) {
inString = trim(inString); // Remove any whitespace characters
brightness = float(inString); // Convert the string to a float value
brightness = map(brightness, 0, 1023, 0, 255); // Map the brightness value to the range 0-255
}
}
I am supposed to see the Processing sketch to read the values and change the color on the screen. However, neither of these is happening despite the photoresist working. I have an LED connected in series which will dim accordingly if I cover the photoresistor.