// Read data from the serial port and assign it to a variable. Set the fill a // rectangle on the screen using the value read from a light sensor connected // to the Wiring or Arduino board import processing.serial.*; Serial port; // Create object from Serial class String val; // Data received from the serial port PImage img; // Background image void setup() { size(627, 418); noStroke(); frameRate(10); // Run 10 frames per second String portName = Serial.list()[1]; //retrieving data from COM10 // Open the port that the board is connected to and use the same speed (9600 bps) port = new Serial(this, portName, 115200); img = loadImage("background1.jpg"); //loading the background image } void draw() { if (0 < port.available()) { // If data is available to read, val = port.readString(); // read it and store it in val } if (val != null) { background(img); fill(152,190,100); // Set fill color with the value read textSize(100); val = val.replace('\n', ' '); text(val + "mm", 150, 250); } else{ println("null");} }