For our pcomp midterm, Lindsey and I decided to add joysticks to the Trumpong game that I built for ICM.
Our plan was to connect two potentiometers to the paddles on the left and the right and map their values to the Y values of the P5 sketch.
We were able to get the serial communication working within an hour or so, but we were getting inconsistent results. The serial connection would work for the first game, but then if we closed the serial server and the sketch and reopened it, it wouldn’t work. Either we wouldn’t get data, or we would get very delayed data.
Here it is on the first test with the potentiometers:
We put in place punctuation and handshaking to make sure we were keeping the serial communication as clean as possible, but this didn’t solve the problem. After much trouble shooting with Benny and Sam, we were able to get it working using a node.js fix.
Even with this fix, we found that when run in the P5 editor the ball would get slower and slower with each game played. We fixed this by running it in the browser, where we didn’t have the problem.
With the code in place, we hooked up two thumb joysticks to the control panel I had made for the project in fabrication.
We had wanted to hook up the joysticks’ buttons and X access for enter and player selection, but it took so long to figure out the serial, so we gave up on that for this project.
Here’s the code for P5 and Arduino: