# I want to control a relay with a button press from a joystick using Game Control Plus and Arduino

**URL:** https://discourse.processing.org/t/i-want-to-control-a-relay-with-a-button-press-from-a-joystick-using-game-control-plus-and-arduino/36153
**Category:** Electronics (Arduino, etc.)
**Created:** [April 6, 2022, 7:38am UTC](https://discourse.processing.org/t/i-want-to-control-a-relay-with-a-button-press-from-a-joystick-using-game-control-plus-and-arduino/36153 "2022-04-06T07:38:54Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [April 15, 2022, 1:04pm UTC](https://discourse.processing.org/t/i-want-to-control-a-relay-with-a-button-press-from-a-joystick-using-game-control-plus-and-arduino/36153/3 "2022-04-15T13:04:52Z")

</div>

Just noticed this discussion so sorry in not replying earlier.  
The first thing to do is check whether Processing is detecting the joystick-button press. Modify the user input function to

```auto
public void getUserInput() {
  trim = vkb.getButton(“TRIM”).pressed();
  println("TRIM pressed " + trim);
}

```

When you run the sketch does it flip between `true` and `false` when you press and release the button?

If it does then the problem is in how you process the input.

I noticed in the draw() method the following statement

```auto
if (trim)
  arduino.digitalWrite(10, Arduino.LOW);
else
  arduino.digitalWrite(10, Arduino.HIGH);

```

So trim is `true` when the button is pressed and `false` otherwise. Now `draw()` is executed approximately 60 times a second so when you press and release the button `trim` is only true for a fraction of a second so the statement `arduino.digitalWrite(10, Arduino.HIGH);` is executed almost all the time so it will appear that the button has not been pressed.

---

_[View the full topic](https://discourse.processing.org/t/i-want-to-control-a-relay-with-a-button-press-from-a-joystick-using-game-control-plus-and-arduino/36153)._
