In this week’s recitation, I built three circuits to practice serial communications between Arduino and Processing.
1. Processing to Arduino
- I changed the multiple variables codes: Port_number 4; and variable_number 1; add “values”; and use map() to change the range of the values;
- I use the tone() function to change the tones on Arduino.
- Somethings about the map() function: In the beginning, I use the map() on the Arduino code. But with Nick’s recommendation, I change the map() on the Processing. Because the computer is better than the Arduino to run the code, so when writing the code, it is reasonable to simplify the code on the Arduino.
I use the mouseX value to control the frequency of the buzzer, with the keyPressed to turn the sound on and off.
2. Arduino to Processing
- I use the multiple variable codes too here.
- I change the ellipse into small spots to imitate the drawing points.
- Later I find the line is not smooth, so I delete the delay in my Arduino.
- Another inconvenience is when there are too many lines or dots on the canvas, It is hard to find the drawing spot, so I continuously changed the color of the spot. The function I used is the one in the former homework.
I use two potentiometers to control the x position of x and y position of y. When I click the mouse, it will clean the canvas.
3. Arduino to Processing and Processing to Arduino
I mixed the step1 and step2 to simultaneously control the Arduino and the Processing. However, the Arduino to Processing works well, but the Processing to Arduino works not well.
I mixed the 1 and 2 together and change the buzzer to the LED.
- When I was writing the code, it is easier to separate the functions and achieve them step by step.
- I learned to use the “example” code in Arduino to quickly check the elements. It is really helpful when debugging.
- Combine the old code with the new ones is efficient and fun.