1 (edited by Joan 2020-08-09 06:08:01)

Topic: illuminate button

illuminate button.

Like we illuminate an LED, it would be nice to be able to illuminate a button.
If we have an application that when pressing the button turns on a relay and when pressing it again we turn it off, it is good to indicate it from the same button.


Sorry, if it's not in this space, please move it.


Thank you.

What you don't know ... Question !! and what you know ... Share !! - By Joan

2

Re: illuminate button

Joan wrote:

illuminate button.

Like we illuminate an LED, it would be nice to be able to illuminate a button.
If we have an application that when pressing the button turns on a relay and when pressing it again we turn it off, it is good to indicate it from the same button.


Sorry, if it's not in this space, please move it.


Thank you.

Welcome to the forum Joan...

Place the button behind an LED (it will still work!), use the "To Front", "Forward One", "Back One", and "To Back" menu controls to get the LED in front of the button.

Obviously you will have to write code in the sketch to "illuminate" the LED (Dark Red, Bright Red, for example....).

Remember that the button is the same as a physical button, and the phone app. will keep on writing a "1" to the button value as long as your finger is on it, only writing a "0" when your finger is removed. You will have to take care of this in code.

Here, I've just made this to show you...

http://remotexy.com/en/editor/d92747f37 … 5f28c0875/

2B, or not 2B, that is the pencil ...

3

Re: illuminate button

OK Daba...
Yesterday I made a similar one and I put a code where it turns on when you press, maintains the state and turns off when you press again. SonOff type.

I was saying it because that way we only use one element and not two.
Thanks for the example.

What you don't know ... Question !! and what you know ... Share !! - By Joan

4 (edited by Joan 2020-08-09 22:53:30)

Re: illuminate button

This is my example:

http://remotexy.com/en/editor/922181bfa … b3b215c09/

And the code:

//////////////////////////////////////////////
//        RemoteXY include library          //
//////////////////////////////////////////////

// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__ESP8266WIFI_LIB_POINT
#include <ESP8266WiFi.h>

#include <RemoteXY.h>

// RemoteXY connection settings
#define REMOTEXY_WIFI_SSID "your ssid"
#define REMOTEXY_WIFI_PASSWORD "your password"
#define REMOTEXY_SERVER_PORT 6377

uint8_t flag1;
uint8_t val01;


// RemoteXY configurate 
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
  { 255,1,0,1,0,33,0,10,13,1,
  1,1,22,22,17,17,29,133,0,65,
  26,23,23,15,15,129,0,21,6,21,
  6,6,82,101,108,101,32,48,49,0 };
 
// this structure defines all the variables and events of your control interface
struct {

    // input variables
  uint8_t button_1; // =1 if button pressed, else =0

    // output variables
  uint8_t led_1_g; // =0..255 LED Green brightness

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0

} RemoteXY;
#pragma pack(pop)

/////////////////////////////////////////////
//           END RemoteXY include          //
/////////////////////////////////////////////

// #define PIN_BUTTON_1 D2    // For NodeMCU V3
#define PIN_BUTTON_1 2          // For ESP8266-01


void setup()
{
  RemoteXY_Init ();
 
  pinMode (PIN_BUTTON_1, OUTPUT);
 
  // TODO you setup code
 
}

void loop()
{
  RemoteXY_Handler ();
 
  if (RemoteXY.button_1==0) flag1=0; // Detects the change of state of the button.
  if ((RemoteXY.button_1==1) && flag1==0){
    if (val01==1){
      val01=0;
    }
    else{
      val01=1;
    }
    flag1=1;
    digitalWrite(PIN_BUTTON_1, val01);
    }
 
   
  RemoteXY.led_1_g = (digitalRead(2)==HIGH)?255:0; 
 
  // TODO you loop code
  // use the RemoteXY structure for data transfer
  // do not call delay()


}

What you don't know ... Question !! and what you know ... Share !! - By Joan

5

Re: illuminate button

I execute the "toggle" function needed by a Push_ON/Push_OFF (latching) button slightly differently, I believe it consume less memory, and possibly easier to understand....

#include "RemoteXY.hpp"

// program variables
bool  button1;        // momentary button
bool  button2;        // latching button
bool  button2_memory;


void setup() 
{
  RemoteXY_Init (); 
}

void loop() 
{ 
  RemoteXY_Handler ();
  
  // Momentary button is easy....
  // the boolean tag button1 will be true if
  // the input data is non-zero
  button1 = RemoteXY.button1;

  // Latching button is a little harder ....
  // test to see if button is pressed
  if(RemoteXY.button2) {
    // now test if not already seen on
    if(!button2_memory) {
      // a new press, so toggle the button
      button2 = !button2;
      // set memory flag as button seen
      button2_memory = true;
    }
  }
  // reset the memory flag when button released
  if(!RemoteXY.button2) button2_memory = false;

  // now drive the LED indicators from the button states
  // each button will be either 0 or 1
  RemoteXY.led1_r = (button1 * 255);
  RemoteXY.led2_r = (button2 * 255);
  
}
2B, or not 2B, that is the pencil ...

6 (edited by Joan 2020-08-10 17:21:39)

Re: illuminate button

Daba wrote:

I believe it consume less memory, and possibly easier to understand...

Congratulations!!! Your code is brilliant. I will rehearse it.

IN CCS I use the toggle function, but in Arduino it doesn't exist and that's why I made this little code.

Sorry,
where i find ... #include  ---> "RemoteXY.hpp"



Thank you!!!!

What you don't know ... Question !! and what you know ... Share !! - By Joan

7

Re: illuminate button

Joan wrote:
Daba wrote:

I believe it consume less memory, and possibly easier to understand...

Congratulations!!! Your code is brilliant. I will rehearse it.

IN CCS I use the toggle function, but in Arduino it doesn't exist and that's why I made this little code.

Sorry,
where i find ... #include  ---> "RemoteXY.hpp"



Thank you!!!!

RemoteXY.hpp is the name of a separate "tab" which contains the source code copied from the web editor.

Using a separate tab makes it easier to update, because once you have copied the source code, you can then go into that tab, do a ctrl-a (select all), then ctrl-v (paste).

The button to create a new tab is on the right of the IDE, just below the serial monitor button.

2B, or not 2B, that is the pencil ...