I made a simple game controlled by potentiometers using p5 for this lab. The general idea of the game is based on targeting a circle, which has a random location. 2 potentiometers control the x and y coordinates of the crosshairs. Any button press on the computer “shoots” at the target. If the target is missed, a score count is incremented, 3 seconds are added, and the target moves to a new random location. Every time the target is shot successfully, it is slightly smaller when it is moved. Two LEDs and a speaker are triggered by serial output from p5. After a shot, if it is successful, the green LED flashes and a high tone is played. In the event of a missed shot, a low tone plays, and the yellow LED flashes. The circuit diagram for the arduino can be seen below.


None of the circuitry is particularly complex.
The Arduino side of this game essentially reads values from the potentiometers, sends them to p5, then sends outputs to the speaker and LEDs if p5 sends values back. Values from the potentiometers are mapped, then serial printed together as a string, with a comma separating them (for parsing reasons). After these values are interpreted by p5, p5 may send a value back, in this case a 10 or 100. If one of these values is sent, depending on the value, different values are sent to the LEDs and the speaker.
The full arduino code can be seen below.
In p5, for setup I create a canvas, and establish global variables. I then generate a circle of size 30 at a random location. This will be the first target. After this, the draw function runs. The draw function prints the current score, and the location of the crosshairs, based on data parsed from the serial monitor (using the serialEvent function). It also handles the timer, which uses the frameCount function to keep a regular clock.
If a key is pressed, the keyPressed function runs. This function generates a range of values around the center of the target circle, which are then used to determine whether the target has been hit. If not, “10” is printed to the serial monitor. If so, “100” is printed instead, 3 seconds are added to the clock, and the target is moved to a new random location. The new target will be slightly smaller, because the radius variable is decremented with every hit.
The full code can be seen below. I did not any of the given files except for the one show below.
Since filming the screen and the Arduino at the same time proved difficult, I filmed each individually as well as together.



















































