Draw rectangles in Processing from data in serial monitor

I have 2 ultrasonic sensors that i have already programmed to print out 2 values of distance in one string seperated by a coma. The values will then be read by processing and it should display 2 seperate rectangles that will lengthen and shorten depending on the distance of the ultrasonic sensors towards an object. If the ultrasonic sensor is closer to an object, the rectangle should shorten and if the sensor is far away from an object, the rectangle should lengthen. But after many tries, the rectangle doesnt want to show if i program it for 2 sensors. It will only show for 1 sensor. Is there something wrong with my draw code?

Hello,

You did not post your complete code.

There are many working examples for receiving serial data from the Arduino in the forum.

You should be doing all of your drawing in draw().

You println() the second value in array but are not using to display a rect().

Keep at it… this is an achievable homework exercise.

:)

1 Like

Hi @axeltheodorus, Have you made progress? If you’d still like help, please post the whole Processing code as text, with the code formatting (so people can instantly copy and run it). The serialEvent is affected by what’s in setup, so need to see that. The ‘whole Arduino sketch’ is not so useful as people won’t have the same peripherals. You could make a small Ard sketch that just prints two fixed values to demonstrate the problem.

As @glv says there are lots of working examples on the forum. Unfortunately there are also lots of ways that things can go wrong.

:slight_smile:

Hi

https://www.arduino.cc/education/visualization-with-arduino-and-processing