top of page
Search
  • Dror Margalit

The Simplest of all Games

Using the basic elements of this week's labs, I wanted to make a simple interactive experience using just buttons and LEDs. I came up with a very simple game: whoever presses their button 20 times first - wins!


When making it, I faced three main challenges. First, I wanted each button to count one press at a time. This required creating two sets of variables for each button and making an "if" statement that only adds 1 to the count when the value changes. When I had the +1 each time a button was "HIGH," the serial monitor counted endlessly, making the LED turn on immediately. Second, I wanted the LED to turn on only when the specific LED's value reached 20. Once I understood the basics of "if-else," this was not too complicated for me. Last, the bit that I struggled with was making it possible only for one LED to "win." As seen in the video above, once the green wins, the red cannot. This meant that if one variable reached 20, the other would not make the LED turn on (even if it did reach 20). To solve it, I conditioned the "digitalWrite" of each LED only if the other one is smaller than or equal to 20.


Pressing game code


Labs


Digital Read & Write

This button switches between which LED is on with a simple "if-else" statement.


This button turns an LED on and keeps it on. If I want it to turn off, I may need to add a variable that indicates whether the LED is on or not (TRUE/FALSE).





As I mentioned in my pressing game, making the Arudino press one time was challenging for me. At first, the button continuously added values as it was pressed.

I fixed it by making the +1 be conditioned to the change in the button state (rather than the button state itself).



Timed presses

Learning about the "millis()" function was very useful. I'm sure it will be helpful for future applications that include timing.




Analog Read

"analogRead" was also very useful, as sensors often provide analog input.


This is my simple "analogRead" code, and another one that uses "map".



Threshold

I wanted to indicate a threshold using an LED (rather than only the serial monitor). To do that, I added an "if" statement that "digitalWrite" is a pin that is connected to an LED when a threshold is reached.





Peak

To measure the pick, I added an "if" statement that prints the peak value only when it is higher than the sensor value and the sensor value is higher than the threshold.




Recent Posts

Peer-to-peer nose interaction

By Joann Myung and Dror Margalit In this project, we attempted to increase our online presence and create a feeling of proximity. Using PoseNet, we made users control their position on the screen base

bottom of page