# 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:** 7

<div class="post-metadata">

**Author:** ![mohitSingh](https://avatars.discourse-cdn.com/v4/letter/m/85f322/32.png) [@mohitSingh](https://discourse.processing.org/u/mohitSingh)\
**Post date:** [June 29, 2020, 3:17pm UTC](https://discourse.processing.org/t/showing-buttons-based-on-a-message-received-by-arduino/22235/7 "2020-06-29T15:17:55Z")

</div>

Just a small follow up question .

This is not giving the desired response.

```auto
void receive( byte[] data, String ip, int port ) {  
  data = subset(data, 0, data.length);
  message = new String( data );
if(message == "ack_on") received = 1;
  if(message == "ack_off") received = 0;
}

```

But this is working as I wanted. What is the difference between the two? It should have been same in my opinion.

```auto
void receive( byte[] data, String ip, int port ) {  
  data = subset(data, 0, data.length);
  message = new String( data );
received = "ack_on".equals(message);
}

```

I will put the full code again just for clarity. The commented portion is the not working portion. I had to modify my code a bit to make it look a bit decent

```auto
import controlP5.*; //import ControlP5 library
import hypermedia.net.*;
UDP udp;  
ControlP5 cp5; 
PImage led_red, led_green, led_white;
PFont font;
String message;
int received = 2;
Boolean breceived;

void setup() { 
  size(300, 300);    

  cp5 = new ControlP5(this);
  font = createFont("Ubuntu Mono Bold", 15);   
  led_red = loadImage("red.png");
  led_green = loadImage("green.png");
  led_white = loadImage("white.png");
  udp = new UDP(this, 6124);
  udp.listen(true);

  // Add the buttons to GUI
  cp5.addButton("ON") //The button
    .setPosition(50, 60) //x and y coordinates of upper left corner of button
    .setSize(70, 50) //(width, height)
    ;
  cp5.addButton("OFF") //The button
    .setPosition(50, 120) //x and y coordinates of upper left corner of button
    .setSize(70, 50) //(width, height)
    ;
}

void draw() { //Same as loop in arduino

  background(150, 150, 150);
  textFont(font); 
  text("Remote Control Interface", 70, 30);  
  image(led_white, 140, 60);
  image(led_white, 140, 120);
  if (received == 1) {
    image(led_green, 140, 60);
    text("Ack for ON", 186, 88);
  }
  if (received == 0) {
    image(led_red, 140, 120);
    text("Ack for OFF", 186, 148);
  }
}

void ON() {

  send("ON");
}

void OFF() {

  send("OFF");
}

void receive( byte[] data, String ip, int port ) { // <-- extended handler

  data = subset(data, 0, data.length);
  message = new String( data );

  //if (message == "ack_on") received = 1;
  //if (message == "ack_off") received = 0;
  breceived = "ack_on".equals(message);
  if(breceived) received =1;
  else if(!breceived) received =0;
  println( "receive: \""+message+"\" from "+ip+" on port "+port );
}

void send(String message) {

  //String message = "ON"; // the message to send
  String ip = "localhost"; // the remote IP address
  int port = 6123; // the destination port

  udp.send( message, ip, port );
}

```

![ack](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/811371f182c426af6609aeaf21db44dc2cd4ab26.png)

---

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