In this recitation, you will complete the following exercises to send data from Arduino to Processing, and vice versa, using serial communication. You will be using the SerialRecord library.
Task #1: Make a Processing Etch-A-Sketch
To see how an Etch-A-Sketch works, you can watch a video here.
Working individually, for this exercise, use Arduino to send two analog values to Processing via serial communication. To do this, build a circuit with two potentiometers and write an Arduino sketch that reads their values and sends them serially. (Use SerialRecord example SendMultipleValues as a basis):
Then, write a Processing sketch that draws a circle and reads those two analog values from Arduino. (Use SerialRecord example ReceiveMultipleValues as a basis). This sketch should modify the circle’s x and y values based on the input from Arduino. Just like an Etch-A-Sketch, one potentiometer should control the circle’s x-axis movement, and the other should control the circle’s y-axis movement.
Once you have this working with a circle, modify the code to use a line instead (like a real Etch-A-Sketch). To do this, you will need to keep track of the previous x and y values so that you can draw a line from there to the new x and y positions. You can use this code as a reference.
Task #2:
Working as pair, write a Processing sketch in which a ball bounces from left to right on the screen. (You can use the fullScreen() function, instead of size(), to make the Processing window occupy the full dimensions of your screen.) Send values from Processing to Arduino based on the position of the bouncing ball. You can start with the example code in SerialRecord, SendMultipleValues. These values should somehow give an indication of when the ball hits the edge of the screen. Then, make a circuit with your Arduino and a servo motor. The corresponding Arduino code should read the serial values from Processing and translate them into movements of the servo motor as if it is hitting the ball. You can use the SerialRecord code as a starter, RecieveMultipleValues. See the animated image below for reference as an example built with two servo motors, you can build it with one instead if you are working individually.
Documentation
For your blog post, this week include documentation of task #1, task #2, and the Homework.
Task #1 Documentation
- Document your process for completing the task: (what went well? what was difficult? any surprises?).
- Include a reflection on the interaction involved.
- Include a video and a screenshot.
- Embed your code.
Task #2 Documentation
- List the name of your pair teammate.
- Document the process for completing the task: (what went well? what was difficult? any surprises? what was your process of teamwork?).
- Include a reflection on the interaction involved.
- Include a video and a screenshot.
- Embed your code.