1

Topic: Skitch/ Source Code Required

Hello friends,
I am new one and do not know many more. I just want to make a simple project with RemoteXY app, detail is given below, any friend can create a simple sketch/ source code for this simple project. Thanks

Switch (On/Off) and One Button (Push Button) both are connected with Relay.
Relay-1 should work with Switch (On/Off)
Relay-2 should work with Button (Push Button)
if
Switch (On/Off) is in "Off" position, Push Button should not work
and
if Switch (On/Off) is in "On" position, Push Button should work.

2 (edited by Guillaume 2019-03-31 18:29:09)

Re: Skitch/ Source Code Required

Welcome smile

Something like this ?

void loop()
{
    static uint8_t switch_PreviousValue = RemoteXY.switch;
    static uint8_t button_PreviousValue = RemoteXY.button;
    
    // if switch value changed
    if ( RemoteXY.switch != switch_PreviousValue )
    {
        digitalWrite( pin_relay1, RemoteXY.switch == 1 ? HIGH : LOW );
        switch_PreviousValue = RemoteXY.switch;
    }
    
    // if switch == 1 and button value changed
    if ( RemoteXY.switch == 1 && RemoteXY.button != button_PreviousValue )
    {
        digitalWrite( pin_relay2, RemoteXY.button == 1 ? HIGH : LOW );
        button_PreviousValue == RemoteXY.button;
    }
}

3

Re: Skitch/ Source Code Required

Kindly update the following complete sketch as required above. I am trying according to your providing sketch but getting errors. Thanks alot.


/*
   -- New project --
   
   This source code of graphical user interface
   has been generated automatically by RemoteXY editor.
   To compile this code using RemoteXY library 2.3.3 or later version
   download by link http://remotexy.com/en/library/
   To connect using RemoteXY mobile app by link http://remotexy.com/en/download/                   
     - for ANDROID 4.1.1 or later version;
     - for iOS 1.2.1 or later version;
   
   This source code is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.   
*/

//////////////////////////////////////////////
//        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 "RemoteXY"
#define REMOTEXY_WIFI_PASSWORD "12345678"
#define REMOTEXY_SERVER_PORT 6377


// RemoteXY configurate 
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
  { 255,2,0,0,0,30,0,8,13,1,
  2,0,23,14,22,11,2,26,31,31,
  79,78,0,79,70,70,0,1,0,28,
  32,12,12,2,31,88,0 };
 
// this structure defines all the variables of your control interface
struct {

    // input variable
  uint8_t switch; // =1 if switch ON and =0 if OFF
  uint8_t button; // =1 if button pressed, else =0

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

} RemoteXY;
#pragma pack(pop)

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

#define PIN_SWITCH 13
#define PIN_BUTTON 14


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

void loop()
{
  RemoteXY_Handler ();
 
  digitalWrite(PIN_SWITCH, (RemoteXY.switch==0)?LOW:HIGH);
  digitalWrite(PIN_BUTTON, (RemoteXY.button==0)?LOW:HIGH);
 
  // TODO you loop code
  // use the RemoteXY structure for data transfer


}

4

Re: Skitch/ Source Code Required

/*
   -- New project --
   
   This source code of graphical user interface 
   has been generated automatically by RemoteXY editor.
   To compile this code using RemoteXY library 2.3.3 or later version 
   download by link http://remotexy.com/en/library/
   To connect using RemoteXY mobile app by link http://remotexy.com/en/download/                   
     - for ANDROID 4.1.1 or later version;
     - for iOS 1.2.1 or later version;
    
   This source code is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.    
*/

//////////////////////////////////////////////
//        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 "RemoteXY"
#define REMOTEXY_WIFI_PASSWORD "12345678"
#define REMOTEXY_SERVER_PORT 6377


// RemoteXY configurate  
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
  { 255,2,0,0,0,30,0,8,13,1,
  2,0,23,14,22,11,2,26,31,31,
  79,78,0,79,70,70,0,1,0,28,
  32,12,12,2,31,88,0 };
  
// this structure defines all the variables of your control interface 
struct {

    // input variable
  uint8_t switch; // =1 if switch ON and =0 if OFF 
  uint8_t button; // =1 if button pressed, else =0

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

} RemoteXY;
#pragma pack(pop)

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

#define PIN_SWITCH 13
#define PIN_BUTTON 14


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

void loop() 
{ 
    RemoteXY_Handler ();
    
    static uint8_t switch_PreviousValue = RemoteXY.switch;
    static uint8_t button_PreviousValue = RemoteXY.button;
    
    // if switch value changed
    if ( RemoteXY.switch != switch_PreviousValue )
    {
        digitalWrite( PIN_SWITCH, RemoteXY.switch == 1 ? HIGH : LOW );
        switch_PreviousValue = RemoteXY.switch;
    }
    
    // if switch == 1 and button value changed
    if ( RemoteXY.switch == 1 && RemoteXY.button != button_PreviousValue )
    {
        digitalWrite( PIN_BUTTON, RemoteXY.button == 1 ? HIGH : LOW );
        button_PreviousValue == RemoteXY.button;
    }
}

5

Re: Skitch/ Source Code Required

i got this error when i try to execute your modified code /sketch. Kindly remove this error. thanks


error: expected ')' before 'switch'

exit status 1
expected unqualified-id before 'switch'

6

Re: Skitch/ Source Code Required

switch is a keyword, you cannot use it as a variable name.

7

Re: Skitch/ Source Code Required

Guillaume wrote:

switch is a keyword, you cannot use it as a variable name.

switch is a keyword

Switch is not
SWITCH is not
sWiTcH is not

etc.

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