2 /* first include Arduino.h, the IDE includes it after irmp*.h ... */
4 /* ... and then chokes on uintX_t ... */
9 /* undefine this if you don't want blinking LED for diagnosis */
11 #define SER_BAUD 115200
13 /* F_INTERRUPTS is the interrupt frequency defined in irmpconfig.h */
14 #define US (1000000 / F_INTERRUPTS)
17 Serial.begin(SER_BAUD);
19 /* greeting string and debugging ouput */
20 Serial.println("IRMP test sketch");
23 Serial.println("Send example: P:02 A:916E C:000F (NEC Taste 1)");
25 pinMode(LED_PIN, OUTPUT);
31 delay(20); /* make sure the greeting string is out before starting */
33 Timer1.initialize(US);
34 Timer1.attachInterrupt(timerinterrupt);
37 IRMP_DATA irmp_data[3];
39 int incomingByte = 0; // for incoming serial data
43 IRMP_DATA* data = &irmp_data[act_data];
44 if (irmp_get_data(data))
47 #if IRMP_PROTOCOL_NAMES == 1
48 Serial.print(irmp_protocol_names[data->protocol]);
52 Serial.print(data->protocol, HEX);
54 Serial.print(data->address, HEX);
56 Serial.print(data->command, HEX);
58 Serial.print(data->flags, HEX);
60 /* Serial.print is asynchronous, so the LED is only flashing very lightly */
63 data->flags = 0; // reset flags!
64 int result = irsnd_send_data(data, TRUE);
67 Serial.println("loop : irsnd_send_data ERROR");
78 if (Serial.available() == 18 && readAndCheck('P') && readAndCheck(':'))
81 data->protocol = readHex() * 16 + readHex();
83 if (readAndCheck(' ') && readAndCheck('A') && readAndCheck(':'))
86 data->address = ((readHex() * 16 + readHex()) * 16 + readHex()) * 16 + readHex();
88 if (readAndCheck(' ') && readAndCheck('C') && readAndCheck(':'))
91 data->command = ((readHex() * 16 + readHex()) * 16 + readHex()) * 16 + readHex();
95 int result = irsnd_send_data(data, TRUE);
98 Serial.print("Send IR data: ");
100 Serial.print(data->protocol, HEX);
102 Serial.print(data->address, HEX);
104 Serial.print(data->command, HEX);
117 /* helper function: attachInterrupt wants void(), but irmp_ISR is uint8_t() */
118 void timerinterrupt()
120 #if 1 // if TSOP receiver can't detect my own IR LED, call both functions:
121 irsnd_ISR(); // call irsnd ISR
122 irmp_ISR(); // call irmp ISR
123 #else // if TSOP receiver also detects my own IR LED, don't receive while sending:
124 if (! irsnd_ISR()) // call irsnd ISR
126 irmp_ISR(); // call irmp ISR
131 static inline void led(int state)
134 digitalWrite(LED_PIN, state);
138 static inline int readAndCheck(int c)
140 return c == Serial.read();
143 static inline int readHex()
145 int c = Serial.read();
146 if (c >= '0' && c <= '9')
151 c |= 0x20; // lowercase
153 if (c >= 'a' && c <= 'f')