1 (edited by husseinsalah76 2017-09-29 09:23:22)

Topic: play click buzzer with Switch control

hi,
i alredy using remoteXY for contol eight switchs using eight channel relay modules, i would like to play tone click when use the switch on/off control,   what is the suitable code to play click ton through buzzer

2

Re: play click buzzer with Switch control

Hello,

This forum is about RemoteXY, which you know how to use, since you know how to control relays with it. You need help with something that isn't related to RemoteXY.

You should search on google for a non blocking tone library for your platform. There will be examples on how to play tones, then you just copy the example and play the tone when the relay state changed.

If you still need help, then you should ask on arduino forum or whatever platform you are using, where there will be many more people able to help you than here smile

3

Re: play click buzzer with Switch control

Guillaume wrote:

Hello,

This forum is about RemoteXY, which you know how to use, since you know how to control relays with it. You need help with something that isn't related to RemoteXY.

You should search on google for a non blocking tone library for your platform. There will be examples on how to play tones, then you just copy the example and play the tone when the relay state changed.

If you still need help, then you should ask on arduino forum or whatever platform you are using, where there will be many more people able to help you than here smile

Thanks for reply, l understood that this forum related to RemoteXY, l already google it but the results not reach to my requirements therefore i think that is can be solved by this forum,
Best regards

4

Re: play click buzzer with Switch control

At least show your code so we can see where you are stuck at.

5

Re: play click buzzer with Switch control

Guillaume wrote:

At least show your code so we can see where you are stuck at.

Iwant just to play tone when switch On or OFF
   

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

// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__SOFTSERIAL
#include <SoftwareSerial.h>

#include <RemoteXY.h>

// RemoteXY connection settings
#define REMOTEXY_SERIAL_RX 0
#define REMOTEXY_SERIAL_TX 1
#define REMOTEXY_SERIAL_SPEED 9600


// RemoteXY configurate 
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
    { 255,8,0,0,0,139,0,6,5,1,
  2,0,4,4,20,7,2,79,78,0,
  79,70,70,0,2,0,4,14,20,7,
  2,79,78,0,79,70,70,0,2,0,
  4,24,20,7,2,79,78,0,79,70,
  70,0,2,0,4,34,20,7,2,79,
  78,0,79,70,70,0,2,0,4,44,
  20,7,2,79,78,0,79,70,70,0,
  2,0,4,54,20,7,2,79,78,0,
  79,70,70,0,2,0,4,64,20,7,
  2,79,78,0,79,70,70,0,2,0,
  4,74,20,7,2,79,78,0,79,70,
  70,0,129,0,28,5,18,5,0,82,
  111,111,109,32,78,111,46,49,0,130,
  0,27,4,29,6,8 }; 
 
// this structure defines all the variables of your control interface
struct {

    // input variable
  uint8_t switch_2; // =1 if switch ON and =0 if OFF
  uint8_t switch_3; // =1 if switch ON and =0 if OFF
  uint8_t switch_4; // =1 if switch ON and =0 if OFF
  uint8_t switch_5; // =1 if switch ON and =0 if OFF
  uint8_t switch_6; // =1 if switch ON and =0 if OFF
  uint8_t switch_7; // =1 if switch ON and =0 if OFF
  uint8_t switch_8; // =1 if switch ON and =0 if OFF
  uint8_t switch_9; // =1 if switch ON and =0 if OFF

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

} RemoteXY;
#pragma pack(pop)

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

#define PIN_SWITCH_2 2
#define PIN_SWITCH_3 3
#define PIN_SWITCH_4 4
#define PIN_SWITCH_5 5
#define PIN_SWITCH_6 6
#define PIN_SWITCH_7 7
#define PIN_SWITCH_8 8
#define PIN_SWITCH_9 9

void setup()
{
  RemoteXY_Init ();
 
  pinMode (PIN_SWITCH_2, OUTPUT);
  pinMode (PIN_SWITCH_3, OUTPUT);
  pinMode (PIN_SWITCH_4, OUTPUT);
  pinMode (PIN_SWITCH_5, OUTPUT);
  pinMode (PIN_SWITCH_6, OUTPUT);
  pinMode (PIN_SWITCH_7, OUTPUT);
  pinMode (PIN_SWITCH_8, OUTPUT);
  pinMode (PIN_SWITCH_9, OUTPUT);

   
  // TODO you setup code

     
       
   
     
}

void loop()
{
  RemoteXY_Handler ();
 
  digitalWrite(PIN_SWITCH_2, (RemoteXY.switch_2==0)?HIGH:LOW);
  digitalWrite(PIN_SWITCH_3, (RemoteXY.switch_3==0)?HIGH:LOW);
  digitalWrite(PIN_SWITCH_4, (RemoteXY.switch_4==0)?HIGH:LOW);
  digitalWrite(PIN_SWITCH_5, (RemoteXY.switch_5==0)?HIGH:LOW);
  digitalWrite(PIN_SWITCH_6, (RemoteXY.switch_6==0)?HIGH:LOW);
  digitalWrite(PIN_SWITCH_7, (RemoteXY.switch_7==0)?HIGH:LOW);
  digitalWrite(PIN_SWITCH_8, (RemoteXY.switch_8==0)?HIGH:LOW);
  digitalWrite(PIN_SWITCH_9, (RemoteXY.switch_9==0)?HIGH:LOW);

  // TODO you loop code
  // use the RemoteXY structure for data transfer


}

6

Re: play click buzzer with Switch control

You should only use digitalWrite when the value of the switch has changed.

void loop()
{
    static uint8_t switch_2_prev = RemoteXY.switch_2;
    if ( switch_2_prev != RemoteXY.switch_2 )
    {
        switch_2_prev = RemoteXY.switch_2;
        digitalWrite(PIN_SWITCH_2, (RemoteXY.switch_2==0)?HIGH:LOW);
        PLAYTONE();
    }
}

7

Re: play click buzzer with Switch control

Many thanks for you  it is finaly working,

8

Re: play click buzzer with Switch control

wink