# Showing buttons based on a message received by arduino

**URL:** <https://discourse.processing.org/t/showing-buttons-based-on-a-message-received-by-arduino/22235>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [June 29, 2020, 4:33am UTC](https://discourse.processing.org/t/showing-buttons-based-on-a-message-received-by-arduino/22235 "2020-06-29T04:33:58Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [June 29, 2020, 7:30am UTC](https://discourse.processing.org/t/showing-buttons-based-on-a-message-received-by-arduino/22235/2 "2020-06-29T07:30:17Z")

</div>

Hi,

Welcome to the community! 😉

Remember that the draw function is being executed roughly 60 times per second. And each time, you are drawing a grey background (btw you could write it like this : `background(150);` by just giving the white value).

Drawing a background is equivalent to clearing the entire screen. So if you display your image inside of your `receive` function, it’s going to display that image on a single frame then next frame, you are going to clear your screen so the image disappear.

Just keep track of a boolean value `received` that is first set to false then whenever you receive a positive answer, put that variable to true. Then display your images in draw accordingly :

```auto
void draw(){
  background(150);
  
  if(received){
    image(led_green, 50, 50);
  }else{
    image(led_red, 50, 50);
  }
}

void receive(...){
  // ...
  if(message == "ack_on") received = true;
  if(message == "ack_off") received = false;
 // ...
}

```

---

_[View the full topic](https://discourse.processing.org/t/showing-buttons-based-on-a-message-received-by-arduino/22235)._
