/** * Author = Elena Chong Date = 11/27/2018 Serial read from ATTINY45 connected with HC-SR04 * * Read data from the serial port and change the width of a rectangle. */ import processing.serial.*; Serial myPort; // Create object from Serial class int val; // Data received from the serial port int rHeight = 100; int x = 10; int y = 10; void setup() { size(500, 200); String portName = Serial.list()[1]; myPort = new Serial(this, portName, 9600); } void draw() { if ( myPort.available() > 0) { // If data is available, val = myPort.read(); // read it and store it in val } background(255); // Set background to white fill(50); rect(x, y, val*10, rHeight); println(val); delay(100); // matching send delay to read correctly }