JESSIE ZHAI
Digital artist
A documentation page of rambling and experimenting.
@jessiehaseyes
jessiejiranzhai@gmail.com WEEK 08PCOMP WEEK8
Physical Computing
Lab 8Seial Communication
Sending Serial Data using Punctuation
For this week’s lab, I continued from the last lab to used two potentiometers as my analog inputs and a pushbutton as my digital input. By putting non-numeric punctuation bytes between two data and a new line, I was also to control the two analog sensor values separately. And it printed out three different set of vaues in the Serial Monitor.
Following that, I followed the lab to create a P5.js sketch and intialized the p5.webserial library like the sketches from the last lab. I realized that it is quite important to map the sensor value to the screen so the circle does not go offscreen.
By turning the two potentiometers, I was able to control where the circle is going on the screen.
Call and Response
For this next part in the lab, we used handshaking to control the flow of the data, allowing data to only be sent to the serial port if there’s an incoming byte. However, once I put the code in, my arduino stopped being connected, even though the P5 sketch is still working fun.
I tried this on two separate days unplugging and replugging the arduino over and over again, and changed up the delay value and used other people’s arduino, I was still not able to make it work.
My code was not able to run and print out hello or any of the messages I put in on the serial monitor. I would love to know what the issuas not able to run and print out hello or any of the messages I put in on the serial monitor. I would love to know what the issue might be here!
Experiment
Since I couldn’t get the handshaking to work, I decided to experiment a bit with what I have. Referencing The Coding Train’s example of a simple snake game on P5, I wanted to create a snake game with my two sensor inputs.
The initial snake game uses four keys including the up and down arrow, and the left and right arrow on the keyboard. I first made the two values to control the four directions, if A1 input is high then go right, if low then go left. However, this didn’t really worked since the values are changing all the time and I can’t turn the potentiometers as far as I want to. So I added previous value variables for both of the sensors to store the previous value, and the direction only changes if it was different from the preious one. I then made some adjustments first to add a threshold value since the values from the sensors are quite unstable and changing all the time, I don’t want that to affect the direction the snake even when I’m not touching it. I set the threshold to 50 so if the current value does not change for more than 50 values from the previous one then the direction of the snake remians the same.
And there I have my two potentiometers as the controller for the snake game, which is unnecessarily hard to play.