Add files via upload

This commit is contained in:
AK-Homberger
2019-09-07 10:12:35 +02:00
committed by GitHub
parent e0b5cd89fd
commit ab1cb54bcc

View File

@@ -1,72 +1,72 @@
/* /*
Code to program 433 MHz KeyFob Code to program 433 MHz KeyFob
Transmitter must be connected to Arduino Pin #10 Transmitter must be connected to Arduino Pin #10
Receiver must be connected to Arduino Pin #7 Receiver must be connected to Arduino Pin #7
*/ */
#include <RCSwitch.h> #include <RCSwitch.h>
unsigned long Key[] = {1000001, 1000002, 1000003, 1000004 }; unsigned long Key[] = {1000001, 1000002, 1000003, 1000004 };
int Keys = sizeof(Key)/sizeof(unsigned long); // Number of keys is calculated atomatically int Keys = sizeof(Key) / sizeof(unsigned long); // Number of keys is calculated atomatically
RCSwitch mySwitch = RCSwitch(); RCSwitch mySwitch = RCSwitch();
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
delay(1000); delay(1000);
Serial.println("Press 'Send' to start programming or press a key on remote to see the value."); Serial.println("Press 'Send' to start programming or press a key on remote to see the value.");
mySwitch.enableTransmit(10); // Transmitter is connected to Arduino Pin #10 mySwitch.enableTransmit(10); // Transmitter is connected to Arduino Pin #10
mySwitch.enableReceive(4); // RF Receiver on inerrupt 4 => that is pin #7 on Micro mySwitch.enableReceive(4); // RF Receiver on inerrupt 4 => that is pin #7 on Micro
// Optional set pulse length. // Optional set pulse length.
// mySwitch.setPulseLength(320); // mySwitch.setPulseLength(320);
// Optional set protocol (default is 1, will work for most outlets) // Optional set protocol (default is 1, will work for most outlets)
// mySwitch.setProtocol(2); // mySwitch.setProtocol(2);
// Optional set number of transmission repetitions. // Optional set number of transmission repetitions.
// mySwitch.setRepeatTransmit(15); // mySwitch.setRepeatTransmit(15);
} }
void loop() { void loop() {
int i; int i;
while (!Serial.available()) { // Receive Key Codes until Send was pressed while (!Serial.available()) { // Receive Key Codes until Send was pressed
if (mySwitch.available()) { if (mySwitch.available()) {
long unsigned int value = mySwitch.getReceivedValue(); long unsigned int value = mySwitch.getReceivedValue();
Serial.print("Received Key: "); Serial.print("Received Key: ");
Serial.println(value); Serial.println(value);
mySwitch.resetAvailable(); mySwitch.resetAvailable();
} }
} }
while (Serial.available()) Serial.read(); while (Serial.available()) Serial.read();
Serial.println(); Serial.println();
for (i = 0; i < Keys; i++) { for (i = 0; i < Keys; i++) {
Serial.print("Sending Key: ");
Serial.print("Sending Key: "); Serial.print(i + 1);
Serial.print(i+1); Serial.print(", Value: ");
Serial.print(", Value: "); Serial.println(Key[i]);
Serial.println(Key[i]); Serial.println("Press 'Send' for next Key.");
Serial.println("Press 'Send' for next Key.");
while (!Serial.available()) {
while (!Serial.available()) { mySwitch.send(Key[i], 24);
mySwitch.send(Key[i], 24); Serial.print(".");
Serial.print("."); delay(100);
delay(100); }
} Serial.println();
Serial.println();
while (Serial.available()) Serial.read(); while (Serial.available()) Serial.read();
} }
Serial.println("Press 'Send' to start programming or press a key on remote to see the value."); Serial.println("Press 'Send' to start programming or press a key on remote to see the value.");
} }