Arduino, Processing, and Ultrasonic Sensor (SR04)

Hi everyone,
I'm working on a project involving an ultrasonic sensor and processing. Today, I was working on using the Arduino to connect with Processing. The following was the coding I used for the Arduino.

#define echoPin 7
#define trigPin 8
#define LEDPin 13

int maximumRange = 200;
int minimumRange = 0;
long duration, distance;

void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LEDPin, OUTPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration/58.2;
if (distance >= maximumRange || distance <= minimumRange){
Serial.println("-1");
digitalWrite(LEDPin, HIGH);
}
else {
Serial.println(distance);
digitalWrite(LEDPin, LOW);
}
delay(50);
}

The following was the coding I used for Processing:

import processing.serial.*;

int numOfShapes = 60;
int shapeSpeed = 2;

Square[] mySquares = new Square[numOfShapes];
int shapeSize, distance;
String comPortString;
Serial myPort;
void setup(){
size(displayWidth,displayHeight);
smooth();
shapeSize = (width/numOfShapes);
for(int i = 0; i<numOfShapes; i++){
mySquares(there should be an i surrounded by [] right after mySquares, but that will not display and make everything italicized)=new Square(int(shapeSize*i),height-40);
}
myPort = new Serial(this, "/dev/tty.usbserial-A603AXV3", 9600);
myPort.bufferUntil('\n');
}
void draw(){
background(0);
delay(50);
drawSquares();
}
void serialEvent(Serial cPort){
comPortString = cPort.readStringUntil('\n');
if(comPortString != null) {
comPortString=trim(comPortString);
distance = int(map(Integer.parseInt(comPortString),1,200,1,height));
if(distance<0){
distance = 0;
}
}
}
void drawSquares(){
int oldY, newY, targetY, redVal, blueVal;
mySquares[0].setY((height-shapeSize)-distance);
for(int i = numOfShapes-1; i>0; i--){
targetY=mySquares[i-1].getY();
oldY=mySquares(there should be an i surrounded by [] right after mySquares, but that will not display and make everything italicized).getY();
if(abs(oldY-targetY)<2){
newY=targetY;
}else{
newY=oldY-((oldY-targetY)/shapeSpeed);
}
mySquares(there should be an i surrounded by [] right after mySquares, but that will not display and make everything italicized).setY(newY);
blueVal = int(map(newY,0,height,0,255));
redVal = 255-blueVal;
fill(redVal,0,blueVal);
rect(mySquares(there should be an i surrounded by [] right after mySquares, but that will not display and make everything italicized).getX(), mySquares(there should be an i surrounded by [] right after mySquares, but that will not display and make everything italicized).getY(),shapeSize,shapeSize);
}
}
boolean sketchFullScreen() {
return true;
}
class Square{
int xPosition, yPosition;
Square(int xPos, int yPos){
xPosition = xPos;
yPosition = yPos;
}
int getX(){
return xPosition;
}
int getY(){
return yPosition;
}
void setY(int yPos){
yPosition = yPos;
}
}

When I combine the two and use the ultrasonic sensor, I am able to swipe my hand across the sensor which causes the squares on Processing to move in a wave. Now, today I also used a tool in Processing called mousePressed, which uses the mouse to move around objects and etcetera (I'm not super knowledgable about everything it can do). I was wondering if anyone knew a way to replace the mousePressed tool with the ultrasonic sensor. What I want to do is be able to place my hand in front of the ultrasonic sensor and make a circle expand, then when my hand is away from the sensor the circle goes back to its original size. Is this possible? And, if so, could anyone be kind enough to help me figure this out? Thank you so much for taking the time to read this, and I apologize if the Processing coding looks strange since I am not able to use the exact symbol I used without it being italicized :confused: