Moduli SRX882 e STX882

 

 

✅ Codice per intercettare i segnali del telecomando (con SRX882)

 

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {
  Serial.begin(9600);
  mySwitch.enableReceive(0); // Pin 2 su Arduino Uno (Interrupt 0)
}

void loop() {
  if (mySwitch.available()) {
    Serial.print("Codice ricevuto: ");
    Serial.print(mySwitch.getReceivedValue());
    Serial.print(" | Bit: ");
    Serial.print(mySwitch.getReceivedBitlength());
    Serial.print(" | Protocollo: ");
    Serial.println(mySwitch.getReceivedProtocol());

    mySwitch.resetAvailable();
  }
}

 

✅ Codice per trasmettere i segnali con il telecomando (con STX882)

 

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

int buttonOpen = 2;  // Pin del pulsante di apertura
int buttonClose = 3; // Pin del pulsante di chiusura
int buttonStop = 4;  // Pin del pulsante di stop

void setup() {
  Serial.begin(9600);
  mySwitch.enableTransmit(10);  // Pin D10 per trasmettere

  // Abilita le resistenze di pull-up interne
  pinMode(buttonOpen, INPUT_PULLUP);  // Pulsante apertura
  pinMode(buttonClose, INPUT_PULLUP); // Pulsante chiusura
  pinMode(buttonStop, INPUT_PULLUP);  // Pulsante stop
}

void loop() {
  // Se il pulsante di apertura è premuto (LOW)
  if (digitalRead(buttonOpen) == LOW) {
    mySwitch.send(111111, 24);  // Invia codice apertura (24 bit)
    delay(100);  // Pausa per evitare ripetizioni troppo veloci
  }

  // Se il pulsante di chiusura è premuto (LOW)
  if (digitalRead(buttonClose) == LOW) {
    mySwitch.send(222222, 24);  // Invia codice chiusura (24 bit)
    delay(100);
  }

  // Se il pulsante di stop è premuto (LOW)
  if (digitalRead(buttonStop) == LOW) {
    mySwitch.send(333333, 24);  // Invia codice stop (24 bit)
    delay(100);
  }
}