# Video Game using inputs from serial

**URL:** <https://discourse.processing.org/t/video-game-using-inputs-from-serial/16024>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [December 1, 2019, 9:19pm UTC](https://discourse.processing.org/t/video-game-using-inputs-from-serial/16024 "2019-12-01T21:19:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![richardw1102](https://avatars.discourse-cdn.com/v4/letter/r/b2d939/32.png) [@richardw1102](https://discourse.processing.org/u/richardw1102)\
**Post date:** [December 1, 2019, 9:19pm UTC](https://discourse.processing.org/t/video-game-using-inputs-from-serial/16024/1 "2019-12-01T21:19:38Z")

</div>

So I am creating a video game, similar to this [https://circuitdigest.com/microcontroller-projects/ping-pong-game-using-arduino-accelerometer#comment-30863](https://circuitdigest.com/microcontroller-projects/ping-pong-game-using-arduino-accelerometer#comment-30863)

I currently have a button thats an input to my arduino and whenever I push it, it is suppose to add a ball. I was able to figure out how the position (on/off) value of the button to processing. But I cant figure out how to write a code that adds an ellipse to the game. Ive tried if statements and all it does is add a ball but when the button is not pressed the ball goes away.

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [December 1, 2019, 11:07pm UTC](https://discourse.processing.org/t/video-game-using-inputs-from-serial/16024/2 "2019-12-01T23:07:49Z")

</div>

You need to use a boolean to set a condition permanently.

Your Code :

```auto
//this will only draw the ellipse if/while the Button is pressed/held
if (buttonPressed == true) {
   ellipse(x, y, w, h);
}

```

How it‘s supposed to be :

```auto
boolean showEllipse = false;

if (buttonPressed) {
   showEllipse = true;
}

if (showEllipse) {
   ellipse(x, y, w, h);
}

```

As for adding ellipses, you can do that with a for loop, where the condition is \< numberOfBalls, which will be increased each time you want to add a ball.

Inside of this for loop you‘ll have to draw each ellipse.

You might also want to have an array for the position/extent of your ellipses.
