/* Author: AnalysIR Website: https://www.AnalysIR.com/blog/ IRforum: https://IRforum.AnalysIR.com/ Release Date: 9th May 2019 Licence: Free to use Distribution: Free to distribute underthe same conditions, provided the Author is credited & a link is included and where possible published to our website above This notice should also be included in any distribution and a link to our website should be included in any related publication. Summary: A solution to display a 'basic' graphical representation of IR signals as received by IRremote. Requirements: This sketch is tested on an Arduino UNO, using pin D2 for the IR receiver. An up-to-date copy of the Arduino IDE is required. Selct the Serial Plotter from the Tools menu of the Arduino IDE Select the correct PORT number for your Arduino from the Tools Menu. Tested on Windows, but should work fine on any platform that runs the Arduino IDE. Limitations: Will not work with very long IR signals, due to the limitation of 500 points available on the X-axis. Support: You can support us by checking out our range of IR remote control modules and applications available in our websop, via the link above. In particular, our AnalysIR application, is a far more advanced tool for analysis, decoding and reverse engineering of all Infrared remote control signals. If you need support for this utility you can open a new topic on out IRforum (linked above). IF you have made improvements, you can post them to out IRforum (linked above) */ #include int recvPin = 2; //select any pin for the IR Receiver IRrecv irrecv(recvPin); decode_results results; uint16_t xScale = 50; //scales the signal across the 500 points available on the X-axis void setup() { // put your setup code here, to run once: Serial.begin(115200); irrecv.enableIRIn(); // Start the receiver } void loop() { if (irrecv.decode(&results)) { // Grab an IR code, when available setScale(); //recalculate the scale for the X-axis for every nes signal received plotIR( xScale * 501, 1); //clear plot area plotIR( USECPERTICK * 2, 1); //start off with a dummy space...for better appearance for (int i = 1; i < results.rawlen; i++) { unsigned long x = results.rawbuf[i] * USECPERTICK; if ((i & 1)) { // odd =>Mark plotIR(x, 2); } else { // even => Space plotIR(x, 1); } } irrecv.resume(); // Prepare for the next IR Signal to be received plotIR( USECPERTICK * 2, 1); //finish off with a dummy space...for better appearance } } void plotIR(uint16_t len, uint8_t yVal) { //Send the 'scaled' data to the Serial Plotter of the Arduino IDE len = (len + xScale / 2) / xScale; //do in 50 uSecs chunks to match IRremote for (uint16_t i = 0; i < len; i++) { Serial.print(0); Serial.print(" "); Serial.println(yVal); } } void setScale(void) { //calculates teh scale for the limited X-axis, such that the IR signal is stretched across the full window. uint32_t sigLen = USECPERTICK * 4; //sum of the duration of the signal in uSecs for (int i = 1; i < results.rawlen; i++) { sigLen += results.rawbuf[i] * USECPERTICK; } xScale = ((sigLen + 500 / 2) / 500); //make sure signal does not go beyond 500 X axis ticks if (xScale == 0) xScale++; //scale should be at least 1 point wide }