Recitation 8: Serial Communication by Liyang Zhu (Tom)

Exercise 1

In this exercise, I made an Etch A Sketch with Arduino and Processing. The Arduino reads the values of two potentiometers and sends to Processing via serial. Then Processing will draw lines based on the values from Arduino.

In the Processing code, I use line() to draw the pattern. Therefore, I have to keep track of the previous x and y values. However, when initiating the variables, previous x and previous y are by default 0. Consequently, one straight line will be drawn at the start, if not all potentiometers are at position 0. To get rid of it, I set previous x and previous y to the current values from potentiometers in the setup() function.

Arduino Code:

Processing Code:

The circuit diagram is as follow:

Here is the video of the final result:

Exercise 2

In this exercise, I made a Processing instrument. When I click on the Processing window, the buzzer will make a sound. And the frequency and duration of the sound are determined by mouse position.

Arduino Code:

Processing Code:

The circuit diagram is as follow:

Here is the video of the final result:

Leave a Reply