RCSwitch- How to control duration of signal?

I’m using the RCSwitch library to signal a PT2272-M4 (momentary) which is then run to a latching relay that needs at least a 10ms signal.

How do I ‘hold’ the signal in the code for a chosen duration? Since I’m having an MCU stand in for a keyfob type remote, I’m essentially trying to replicate a held button.

I assume the keyfob just constantly sends the same code quicker than whatever response threshold there is on the receiving chip? Maybe I need to use a while function which spams the send code command? Or set the number of repetitions to coincide with however long that would take? :confused:

Not sure what pulse length parameter does, I think that’s protocol related and not just ‘on’ duration. Could be wrong, but it wasn’t working as expected (pulse duration for (1000) didn’t keep a signal for 1 second)

Provided example code, pared down

/*
  Example for different sending methods
  
  https://github.com/sui77/rc-switch/
  
*/

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {

  Serial.begin(9600);
  
  // Transmitter is connected to Arduino Pin #10  
  mySwitch.enableTransmit(10);

  // Optional set pulse length.
  // mySwitch.setPulseLength(320);
  
  // Optional set protocol (default is 1, will work for most outlets)
  // mySwitch.setProtocol(2);
  
  // Optional set number of transmission repetitions.
  // mySwitch.setRepeatTransmit(15);
  
}

void loop() {

  mySwitch.send(5393, 24);
  delay(1000);  
  mySwitch.send(5396, 24);
  delay(1000);  


  delay(20000);
}

Just doing

void loop() {

  mySwitch.send(5393, 24);
  mySwitch.send(5393, 24);
  mySwitch.send(5393, 24);
  mySwitch.send(5393, 24);

...

gives an appreciable duration which will work, just doesn't seem very elegant.

A bit late but it might be useful to someone else trying to do the same:

  • setPulseLength should not be used to change the 'length' of the transmission, as it is the length of the pulse associated to the single bit being transmitted: changing it might render the sequence invalid for the receiver
  • you should use the setRepeatTransmit method to do what you want: it simply keeps sending the code again and again for the specified number of times (it defaults to 10 on my version of wiring pi)

The pulse length depends on the protocol used, however you can keep this as a reference if you want precise timing for your code to be "on air" (comment on line 52 in RCSwitch.cpp of wiring pi):

/* Format for protocol definitions:
 * {pulselength, Sync bit, "0" bit, "1" bit}
 * 
 * pulselength: pulse length in microseconds, e.g. 350
 * Sync bit: {1, 31} means 1 high pulse and 31 low pulses
 *     (perceived as a 31*pulselength long pulse, total length of sync bit is
 *     32*pulselength microseconds), i.e:
 *      _
 *     | |_______________________________ (don't count the vertical bars)
 * "0" bit: waveform for a data bit of value "0", {1, 3} means 1 high pulse
 *     and 3 low pulses, total length (1+3)*pulselength, i.e:
 *      _
 *     | |___
 * "1" bit: waveform for a data bit of value "1", e.g. {3,1}:
 *      ___
 *     |   |_
 *
 * These are combined to form Tri-State bits when sending or receiving codes.
 */