1 (edited by 3dnour 2019-04-11 10:07:07)

Topic: Switch

welcome everybody ......

I'm working on NodeMCU V3

How can I add an external key to the light with the application RemoteXY
On the mobile so that I can turn on and turn off the light by mobile
  At the same time I want to turn on and off the light through an external key
  And know the status of the key in mobile ..


I wish you all the health........ smile


  Thanks

2

Re: Switch

Sadly it's not possible... This has been asked and requested many many times since years, and it's still not possible to do this simple thing.

3

Re: Switch

Thanks for your nice response

4

Re: Switch

Maybe you know already, but what you can do instead is to have two Buttons On and Off, and a Led or Text indicator to show the actual status of the light.

5

Re: Switch

Another trick is to put a Button with no text, then on top of it you put a Text String. You will be able to press the Button even if there is a Text String above it. Then you update the Text String according to the state of the light.

For example:

// In setup, after RemoteXY_Init() :
strcpy( RemoteXY.textButtonLight, "ON" );

//In loop() :
static uint8_t buttonLight_previousValue = RemoteXY.buttonLight;
static bool lightState = false;
if ( RemoteXY.buttonLight != buttonLight_previousValue )
{
  buttonLight_previousValue = RemoteXY.buttonLight;
      
  if ( RemoteXY.buttonLight == 1 )
  {
    lightState = !lightState;
    strcpy( RemoteXY.textButtonLight, lightState == true ? ("OFF") : ("ON") );
    digitalWrite( PIN_LIGHT, lightState == true ? HIGH : LOW );
  }
}

6

Re: Switch

Guillaume wrote:

Another trick is to put a Button with no text, then on top of it you put a Text String. You will be able to press the Button even if there is a Text String above it. Then you update the Text String according to the state of the light.

For example:

// In setup, after RemoteXY_Init() :
strcpy( RemoteXY.textButtonLight, "ON" );

//In loop() :
static uint8_t buttonLight_previousValue = RemoteXY.buttonLight;
static bool lightState = false;
if ( RemoteXY.buttonLight != buttonLight_previousValue )
{
  buttonLight_previousValue = RemoteXY.buttonLight;
      
  if ( RemoteXY.buttonLight == 1 )
  {
    lightState = !lightState;
    strcpy( RemoteXY.textButtonLight, lightState == true ? ("OFF") : ("ON") );
    digitalWrite( PIN_LIGHT, lightState == true ? HIGH : LOW );
  }
}

I have done similar, but I have found that you don't need to remember "xxx_previousValue" if you immediately write the RemoteXY input OFF as soon as you see it ON, RemoteXY interface can write it OFF again later, but it will have no effect.  This creates a"one-shot" effect that works a treat.

Your code could be simplified to ....

// In setup, after RemoteXY_Init() :
strcpy( RemoteXY.textButtonLight, "ON" );

//In loop() :
if (RemoteXY.buttonLight)  // evaluates as "true" if non-zero
{
  RemoteXY.buttonLight = 0;
  lightState = !lightState;   // invert the lightstate
  strcpy( RemoteXY.textButtonLight, lightState == true ? ("OFF") : ("ON") );
  digitalWrite( PIN_LIGHT, lightState);
  }
}
Everything works with smoke - if you let it out, things stop working....

7 (edited by Guillaume 2019-04-17 19:43:50)

Re: Switch

Sometimes I like to do an action when the button is released so I have the habit of using my method, but yours is nice too if you don't care about releasing tongue

8 (edited by Daba 2019-04-23 11:24:35)

Re: Switch

Guillaume wrote:

Sometimes I like to do an action when the button is released so I have the habit of using my method, but yours is nice too if you don't care about releasing tongue

It is a shame that the app doesn't emulate a "proper" touch-screen interface, so that you can do "mouse-down", "mouse-over", and "mouse-up" etc.

Since it is a simple button, with only two states "down" and "up", and there's no getting away from that. So, yes, if you want "button-up" you have to do it in code, like your suggestion.  But without the intelligence in the app, if you press a button and change your mind, you cannot just drag your finger off the button and take your finger off the screen, like you can with a mouse.

Everything works with smoke - if you let it out, things stop working....