After fixing the issues with serial control on my computer I decided to do some research into media controls with p5. Initially I wanted to have 5 videos in a playlist and have the potentiometer cycle between them when turned, but after spending about 2 hours trying and failing I gave up on that and moved on. One of the fun things I came across in my research was the ability to control the speed of media via a slider, so I chose to adapt this to use the potentiometer as the slider. After a bit of experimentation I made it work. I then decided that I needed a better song than one of the windows default sounds, so I chose the Seinfeld theme as it’s the most beautiful ballad ever constructed (fun fact it was rerecorded for every single episode of Seinfeld to match the tone and length of Jerry’s monologue at the beginning of each episode.)
I modified my sketch from last week so that the user can control the x-axis of the bouncing color ball with input from a potentiometer. The ball still bounces up and down by itself but the user can make the ball go left or right by twisting the potentiometer.
For the Serial homework assignment, I extended last week’s homework to use an Arduino to control the paddles. To do this, I put together a circuit with three inputs: two potentiometers and a button. The potentiometers control the location of the paddle, while the button starts the game again when someone has scored. This is what the circuit looks like:
I then had to change a few things in my pong game code. After setting up the code for Serial, I changed the Paddle class to only have one method to change its location: setY. This function takes in the y coordinate of the paddle and changes it to that, so that I can simply pass in the location of the paddle based on the inputs from the potentiometers. Because I’m using the potentiometers to determine the location of the paddles, it actually simplified the code, specifically the Paddle class. It used to take in a lot more information like the paddle speed, the boundaries of the canvas, and the keys to control the paddle. Here’s a video demo of the game:
At the end the input started to lag a lot so I couldn’t continue to film it. I think it has to do with the whole Serial set up being somewhat inefficient, but I’m not exactly sure how to fix it. It also seems to take up a lot of RAM and my laptop can’t really run all of the programs at once.
I built off the same code as last time where there’s and alien spaceship chasing a sheep and the sheep gets levitated up and down. This time I made it so the levitation movement of the sheep is controlled by the potentiometer. I had the map the function to my canvas (may have overshot it a bit since the sheep can still disappear) and attach y movement to the rating from the potentiometer. It still needs more components to make it an actual game though (object with functions, a way to win etc). The potentiometer gives it a cool arcade feel, but I wouldn’t play it in an arcade yet. Maybe next week.
I built off of last week’s assignment by adding a potentiometer to a p5 program. The goal was to use the potentiometer to control the movement of the moon. I had actually wanted to control the movement of the moon in the Y direction, but I wasn’t sure if I’d be able to, so I tried to make sure I could move it along the X axis. Here, I ran into a problem, the moon would not pass 255.
After struggling, I learned that the Serial Port in p5 doesn’t read more than 255, so I would have to map the reading in p5 to the width of my canvas to get a full range of motion. From there I decided to go ahead and use the potentiometer to control the Y movement of the moon, this time only allowing the moon to move from Y 100 to 300, mapping this made the circle’s movement much less sensitive to the turns of the potentiometer. I had also wanted to make it so that when the circle reached a certain altitude, bits of red would creep in from the edges of the canvas. While I got the gradient to be about what I wanted, I had difficulty animating it and abandoned that effort.
The video below shows the program in action. It would be best to watch it on mute.
For this assignment I used a potentiometer to control how many balls were bouncing from my last project. I mapped the values from 0 to 10, and added a delay so the balls wouldn’t change to fast. It takes away balls if it is moving to the left and adds if it is twisted to the right, this may be different if you plug your potentiometer in with the positive and grounded ends switched because I used the difference between the last and current number. However depending on how fast it registers the balls don’t always show up as expected.