disable transmit pin when idle to avoid noise

This commit is contained in:
Nicu Hodos 2023-12-18 14:53:02 +01:00
parent 4a3c54b024
commit 14f41cf0f9
4 changed files with 23 additions and 5 deletions

View File

@ -1,6 +1,6 @@
#pragma once
#include <ArduinoJson.h>
#include <RCSwitch.h>
#include "RC.h"
class Protocol {
protected:
@ -15,7 +15,9 @@ public:
virtual void fromJson(JsonObjectConst& rcSwitch, RCSwitch& rcDevice) {
unsigned int protocol = rcSwitch["protocol"];
rcDevice.setProtocol(protocol);
mySwitch.enableTransmit(SEND_PIN);
rcDevice.send(rcSwitch["value"]);
mySwitch.disableTransmit();
}
virtual void toJson(unsigned long value, JsonDocument& jsonDoc) {

View File

@ -1,4 +1,5 @@
#pragma once
#include "RC.h"
#include "Protocol.h"
#include "RcDecoder.h"
@ -13,7 +14,9 @@ public:
rcDevice.setProtocol(protocol);
const char* group = rcSwitch["group"];
int channel = rcSwitch["channel"];
mySwitch.enableTransmit(SEND_PIN);
rcSwitch["state"] ? rcDevice.switchOn(group, channel) : rcDevice.switchOff(group, channel);
mySwitch.disableTransmit();
}
void toJson(unsigned long value, JsonDocument& jsonDoc) override {

15
gateway/include/RC.h Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include <RCSwitch.h>
#define SEND_PIN 11
#define RECEIVE_PIN 2
RCSwitch mySwitch;
namespace RC {
void setup() {
mySwitch.enableReceive(digitalPinToInterrupt(RECEIVE_PIN));
mySwitch.setRepeatTransmit(10);
}
}

View File

@ -1,6 +1,7 @@
#include <Arduino.h>
#include <RCSwitch.h>
#include "Dht.h"
#include "RC.h"
#include "Protocol_1.h"
#include "Protocol_2.h"
#include "output.h"
@ -19,10 +20,7 @@ void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(RESET_PIN, OUTPUT);
mySwitch.enableReceive(digitalPinToInterrupt(RECEIVE_PIN));
mySwitch.enableTransmit(SEND_PIN);
mySwitch.setRepeatTransmit(10);
RC::setup();
Dht::setup();
Serial.begin(9600);