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 (edited by Guillaume 2020-07-24 19:32:05)

Re: Switch

Edit: see below

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);
  }
}
2B, or not 2B, that is the pencil ...

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.

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

9 (edited by albatros 2019-06-03 05:44:44)

Re: Switch

At Least I Get my code for my Idea using 1 Relay to Control Multiple Command, using Select Button, and works

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

// RemoteXY select connection mode and include library 
#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT

#include <RemoteXY.h>

// RemoteXY connection settings 
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_WIFI_SSID "UsingSelectButton"
#define REMOTEXY_WIFI_PASSWORD ""
#define REMOTEXY_SERVER_PORT 6377


// RemoteXY configurate   
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
  { 255,3,0,0,0,45,0,8,13,0,
  2,0,4,7,22,11,2,26,31,31,
  79,78,0,79,70,70,0,2,0,4,
  25,22,11,2,26,31,31,79,78,0,
  79,70,70,0,3,3,5,39,8,22,
  2,26 };
   
// this structure defines all the variables of your control interface 
struct {

    // input variable
  uint8_t switch_1; // =1 if switch ON and =0 if OFF
  uint8_t switch_2; // =1 if switch ON and =0 if OFF
  uint8_t select_1; // =0 if select position A, =1 if position B, =2 if position C, ...
 
    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0

} RemoteXY;
#pragma pack(pop)

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

#define PIN_SWITCH_1 2
#define PIN_SWITCH_2 2
#define PIN_SELECT_1 2

int i;

void setup() 
{
  RemoteXY_Init (); 
   
  pinMode (PIN_SWITCH_1, OUTPUT);
  pinMode (PIN_SWITCH_2, OUTPUT);
  pinMode (PIN_SELECT_1, OUTPUT);
   
  // TODO you setup code
   
}

void loop() 

  RemoteXY_Handler ();
   
  digitalWrite(PIN_SWITCH_1, (RemoteXY.switch_1==0)?HIGH:LOW);
      if(RemoteXY.switch_1==1)
    {
    digitalWrite (PIN_SWITCH_1, HIGH);//Lampu Switch Mati
    delay(1000);
    digitalWrite (PIN_SWITCH_1, LOW);//Lampu Switch Hidup
    delay(3000);
    }

  digitalWrite(PIN_SWITCH_2, (RemoteXY.switch_2==0)?HIGH:LOW);
    if(RemoteXY.switch_2==1)
    {
    digitalWrite (PIN_SWITCH_2, HIGH);//Lampu Switch Mati
    delay(500);
    digitalWrite (PIN_SWITCH_2, LOW);//Lampu Switch Hidup
    delay(500);
    }

//Select Button Code

  digitalWrite(PIN_SWITCH_1, (RemoteXY.select_1==0)?HIGH:LOW);
  if(RemoteXY.select_1==1)
    {
      for(i=0; i<5; i++)
      {
       digitalWrite(PIN_SWITCH_1,HIGH);
       delay(500);
       digitalWrite(PIN_SWITCH_1,LOW);
       delay(500);
      }
      delay(10000);
    }
   
  if(RemoteXY.select_1==2)
  {
    digitalWrite(PIN_SELECT_1,HIGH);
    delay(1000);
    digitalWrite(PIN_SELECT_1,LOW);
    delay(3000);
  }
  // TODO you loop code
  // use the RemoteXY structure for data transfer
}

Thanks all
I will upgrade my Washing Machine and control it using my Android Wireless via WIFI
but I have another question to solve, "how to stop Looping after amount of time?"

Newbie Arduino from Bali - Indonesia
bit.ly/chat_sandy for my WA Chat Link

10 (edited by quietfire 2019-06-24 00:03:49)

Re: Switch

Guillaume wrote:

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.


Sigh... I want to do things with RemotXY.  I look for the answer's and so often I find you saying this.  Guillaume, to you have a document of can't do with RemoteXY?  LOL.

Seriously this is such a great app, but the limitations like not being able to turn a switch back off from the sketch, or not getting a flag sent to the sketch on page change...

11

Re: Switch

sad

12

Re: Switch

This feature was added recently, see here http://forum.remotexy.com/viewtopic.php?id=1034