Lab 4: Serial
The purpose of this lab was to create a game using two inputs and one Arduino output. The game itself was created using P5.js and serial communication. For my game, I utilized a potentiometer and a light sensor to control a one-person game of pong based on Coding Train’s example.
The game is an unwinnable game of Pong where the opponent is a static wall. There is also no means of scoring, either in time or points, rendering the game an exercise in futility.
The Circuit
The Arduino circuit uses a potentiometer, a lights sensor with a 10k dropdown resistor, and a 5 LED strip of Neopixels. The potentiometer controls the paddle, the light controls the speed of the ball, and the LEDs display how many lives the payer has left
The Arduino Code
The Arduino code first sets up the pins and the strip. Next, it sends the values from the analog pins to P5. Lastly, it checks for serial input and changes the Neopixel accordingly.
The P5 Code
The P5 code is based on Coding Train’s Pong example. I mostly used this as a basis for how to do collision detection and general code structure. I also added a game state to pause the game when the player eventually loses. Since the draw function is based on FPS, I was able to use that was a makeshift timer.
The Game
You just lost The Game.