Created
May 5, 2022 04:48
-
-
Save remotephone/8280e83c90de963165609f7886c43146 to your computer and use it in GitHub Desktop.
WWHF2022 lab code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Receiver board sketch | |
*/ | |
#include <RCSwitch.h> | |
#include "output.h" | |
#define LED 2 | |
int buttonA = 952424; | |
int buttonB = 952420; | |
RCSwitch mySwitch = RCSwitch(); | |
void setup() { | |
// Set pin mode | |
pinMode(LED, OUTPUT); | |
Serial.begin(9600); | |
mySwitch.enableReceive(16); // Receiver on interrupt 0 => that is pin #2 on Uno –> Pin 16 on ESP32 WROOM | |
} | |
void loop() { | |
if (mySwitch.available()) { | |
output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(), mySwitch.getReceivedProtocol()); | |
if (mySwitch.getReceivedValue() == buttonA) { | |
delay(500); | |
digitalWrite(LED, HIGH); | |
} | |
if (mySwitch.getReceivedValue() == buttonB) { | |
delay(500); | |
digitalWrite(LED, LOW); | |
} | |
mySwitch.resetAvailable(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Receiver board sketch | |
*/ | |
#include <RCSwitch.h> | |
#include "output.h" | |
#define LED 2 | |
int buttonA = 952424; | |
int buttonB = 952420; | |
RCSwitch mySwitch = RCSwitch(); | |
void setup() { | |
// Set pin mode | |
pinMode(LED, OUTPUT); | |
Serial.begin(9600); | |
mySwitch.enableReceive(16); // Receiver on interrupt 0 => that is pin #2 on Uno –> Pin 16 on ESP32 WROOM | |
} | |
void loop() { | |
if (mySwitch.available()) { | |
output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(), mySwitch.getReceivedProtocol()); | |
if (mySwitch.getReceivedValue() == buttonA) { | |
delay(500); | |
digitalWrite(LED, HIGH); | |
} | |
if (mySwitch.getReceivedValue() == buttonB) { | |
delay(500); | |
digitalWrite(LED, LOW); | |
} | |
mySwitch.resetAvailable(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Transmitter-sketch | |
/* | |
Example replay previously captured 433 MHz RF signal | |
*/ | |
#include <RCSwitch.h> | |
RCSwitch mySwitch = RCSwitch(); | |
void setup() { | |
Serial.begin(9600); | |
// Transmitter is connected to ESP32 WROOM #16 | |
mySwitch.enableTransmit(16); | |
// Optional set protocol (default is 1, will work for most outlets) | |
mySwitch.setProtocol(1); | |
// Optional set pulse length (used the viewed Spectrogram pulse length data in uSeconds, also appears in Arduino Rcv’d serial output) | |
mySwitch.setPulseLength(356); | |
// Optional set number of transmission repetitions (default is 10 reps) | |
mySwitch.setRepeatTransmit(15); | |
} | |
void loop() { | |
/* using binary code NEW KEY FOB — A – B*/ | |
mySwitch.send("000011101000100001101000"); | |
delay(1000); | |
mySwitch.send("000011101000100001100100"); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment