2 * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
3 * An IR detector/demodulator must be connected to the input RECV_PIN.
4 * Version 0.1 July, 2009
5 * Copyright 2009 Ken Shirriff
14 IRrecv irrecv(RECV_PIN);
15 decode_results results;
17 // Dumps out the decode_results structure.
18 // Call this after IRrecv::decode()
19 // void * to work around compiler issue
20 //void dump(void *v) {
21 // decode_results *results = (decode_results *)v
22 void dump(decode_results *results) {
23 int count = results->rawlen;
24 if (results->decode_type == UNKNOWN) {
25 Serial.println("Could not decode message");
28 if (results->decode_type == NEC) {
29 Serial.print("Decoded NEC: ");
31 else if (results->decode_type == SONY) {
32 Serial.print("Decoded SONY: ");
34 else if (results->decode_type == RC5) {
35 Serial.print("Decoded RC5: ");
37 else if (results->decode_type == RC6) {
38 Serial.print("Decoded RC6: ");
40 Serial.print(results->value, HEX);
42 Serial.print(results->bits, DEC);
43 Serial.println(" bits)");
45 Serial.print("Raw (");
46 Serial.print(count, DEC);
49 for (int i = 0; i < count; i++) {
51 Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
54 Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
63 pinMode(RELAY_PIN, OUTPUT);
66 irrecv.enableIRIn(); // Start the receiver
70 unsigned long last = millis();
73 if (irrecv.decode(&results)) {
74 // If it's been at least 1/4 second since the last
75 // IR received, toggle the relay
76 if (millis() - last > 250) {
78 digitalWrite(RELAY_PIN, on ? HIGH : LOW);
79 digitalWrite(13, on ? HIGH : LOW);
83 irrecv.resume(); // Receive the next value