Push Button Test

Thesis

Before I start setting up my arcade buttons, I need to make sure that I can reliably send messages with basic push buttons on a breadboard. For testing purposes, I’m just using three buttons instead of seven—a red, green, and blue button to represent red, green, and blue flowers.

I needed to detect state change in any of the three buttons. This is crucial, because I only want to send a message when a button is moving from LOW to HIGH—otherwise I’ll clog up the serial port with unnecessary information.

In Javascript I would create a “button object” or “flower object” but I don’t think such a thing exists in C. So instead I made a series of corresponding arrays: one for pin numbers, one for the current states, one for the previous states, and one for the message to be sent (the color of the flowers). Then I used two for loops: one to declare each button pin as an input, and one to read the pins and test for state change.

The code totally works! On to the p5 side of things.

Leave a Reply

Your email address will not be published. Required fields are marked *