Lucid Projects

Blog - Day to day mumblings...
P5 Serial Connection

P5 Serial Connection

17 Oct 2019 - Jake Sherwood

Control Consume the Earth with serial connected push buttonsl Control Consume the Earth with serial connected push buttons

PCOMP WEEK 6 - Serial connect to a p5 sketch - Consume the Earth pt 2.

The this week in pcomp we explored connecting to p5 js with the serial port and the p5 serial control app.

It was pretty cool to instantly see the stuff we’ve been doing solely on the web suddenly take on a physical aspect.

We were tasked to expand on the labs and interact with one of our p5 sketches. I had the perfect sketch… the consume the earth game I had just made for ICM.

I built the p5 sketch to work off of key presses on the left and right arrows.

Basically it creates arrays of tree and consume elements and you create them by key press. Who ever has the most out of certain number wins and the earth either lives or dies.

First things first I had to adapt my serial connected sketch to work with push buttons instead of the pot.

I first tried with a button state change sketch but p5 was having issues with it.

Simplifying it to just check for a 1 or 0 in a couple if statements made everybody agree and I was now able to control a p5 sketch with push buttons.

To further prove it out, I change the ball position based on the button press.

p5 serial connected sketch moving ball based button press

Having that sorted I was ready to make changes to my consume the earth p5 sketch and either save or kill the earth.

I set up 2 separate breadboards for the push buttons with the idea that it could be a 2 person game.

The p5 sketch checks the inData variable for a certain string and if its there it runs a plantTrees() or consume() function.

Consume the Earth by button press - serial connection

p5 Sketch

categories: pcomp

join me on this crazy ride. enter your email:

contact [at] jakesherwood [dot] com

contact me if you'd like to work together