2021-01-05 00:15:16 -03:00
|
|
|
#include <IRremote.h>
|
|
|
|
int RECV_PIN = 11;
|
|
|
|
|
|
|
|
IRrecv irrecv(RECV_PIN);
|
|
|
|
decode_results results;
|
|
|
|
// Dumps out the decode_results structure.
|
|
|
|
// Call this after IRrecv::decode()
|
|
|
|
// void * to work around compiler issue
|
|
|
|
//void dump(void *v) {
|
|
|
|
// decode_results *results = (decode_results *)v
|
|
|
|
void dump(decode_results *results) {
|
2022-04-04 17:41:38 -04:00
|
|
|
int count = results->rawlen;
|
|
|
|
if (results->decode_type == UNKNOWN) {
|
|
|
|
Serial.println("Could not decode message");
|
|
|
|
} else {
|
|
|
|
if (results->decode_type == NEC) {
|
|
|
|
Serial.print("Decoded NEC: ");
|
|
|
|
} else if (results->decode_type == SONY) {
|
|
|
|
Serial.print("Decoded SONY: ");
|
|
|
|
} else if (results->decode_type == RC5) {
|
|
|
|
Serial.print("Decoded RC5: ");
|
|
|
|
} else if (results->decode_type == RC6) {
|
|
|
|
Serial.print("Decoded RC6: ");
|
2021-01-05 00:15:16 -03:00
|
|
|
}
|
2022-04-04 17:41:38 -04:00
|
|
|
Serial.print(results->value, HEX);
|
|
|
|
Serial.print(" (");
|
|
|
|
Serial.print(results->bits, DEC);
|
|
|
|
Serial.println(" bits)");
|
2021-01-05 00:15:16 -03:00
|
|
|
}
|
|
|
|
Serial.print("Raw (");
|
|
|
|
Serial.print(count, DEC);
|
|
|
|
Serial.print("): ");
|
|
|
|
|
2022-04-04 17:41:38 -04:00
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
if ((i % 2) == 1) {
|
|
|
|
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
|
|
|
|
} else {
|
|
|
|
Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
|
|
|
|
}
|
|
|
|
Serial.print(" ");
|
2021-01-05 00:15:16 -03:00
|
|
|
}
|
2022-04-04 17:41:38 -04:00
|
|
|
Serial.println("");
|
2021-01-05 00:15:16 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void setup() {
|
2022-04-04 17:41:38 -04:00
|
|
|
pinMode(RECV_PIN, INPUT);
|
|
|
|
pinMode(13, OUTPUT);
|
|
|
|
Serial.begin(9600);
|
|
|
|
irrecv.enableIRIn(); // Start the receiver
|
2021-01-05 00:15:16 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
int on = 0;
|
|
|
|
unsigned long last = millis();
|
|
|
|
void loop() {
|
2022-04-04 17:41:38 -04:00
|
|
|
if (irrecv.decode(&results)) {
|
|
|
|
// If it's been at least 1/4 second since the last
|
|
|
|
// IR received, toggle the relay
|
|
|
|
if (millis() - last > 250) {
|
|
|
|
on = !on;
|
|
|
|
//digitalWrite(8, on ? HIGH : LOW);
|
|
|
|
digitalWrite(13, on ? HIGH : LOW);
|
|
|
|
dump(&results);
|
|
|
|
}
|
|
|
|
last = millis();
|
|
|
|
irrecv.resume(); // Receive the next value
|
2021-01-05 00:15:16 -03:00
|
|
|
}
|
2022-04-04 17:41:38 -04:00
|
|
|
}
|