Skip to content

Instantly share code, notes, and snippets.

@ThomazPom
Last active June 4, 2022 17:44
Show Gist options
  • Save ThomazPom/9ec4d0ef4984bed418116d4c14203287 to your computer and use it in GitHub Desktop.
Save ThomazPom/9ec4d0ef4984bed418116d4c14203287 to your computer and use it in GitHub Desktop.
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
int emit(int value=1008,int protocol=6,int wordlen=12)
{
String must_send = intToBinaryWord(value,wordlen);
mySwitch.send(must_send.c_str());
Serial.print("Protocol : ");
Serial.print( protocol );
Serial.print( " Emited value: " );
Serial.print( value );
Serial.print( " = " );
Serial.println( must_send.c_str() );
return 1;
}
String intToBinaryWord(int num,int bitsCount)
{
char str[ bitsCount + 1 ];
int i = 0;
while ( bitsCount-- )
str[ i++ ] = bitRead( num, bitsCount ) + '0';
str[ i ] = '\0';
return str;
}
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // That is pin #2
mySwitch.enableTransmit(10); // Pin 10
mySwitch.setPulseLength(433); // MHZ
mySwitch.setRepeatTransmit(5); //Repeat number
Serial.println("Device Online !");
emit(1008,6);
}
void loop() {
if (mySwitch.available()) {
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.print(mySwitch.getReceivedProtocol());
Serial.print(" Pulse lenght: ");
Serial.print(mySwitch.getReceivedDelay());
// Serial.print("Raw Data: ");
// Serial.print(mySwitch.getReceivedRawdata());
Serial.println();
mySwitch.resetAvailable();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment