   // Wait for an event from the IR receiver
   Event event;
   Event::queue.await(&event);
+  uint8_t type = event.get_type();
 
-  // Print the received remote code
-  receiver.print(trace);
-
-  // Print the posted event code. This is the code that should be used
-  uint16_t code = event.get_value();
-  INFO("event.value:code = %hd", code);
-  Watchdog::delay(512);
-
-  // Reset to allow the next code sequence
+  // Check if a new reading from the IR receiver was completed
+  if (type == Event::READ_COMPLETED_TYPE) {
+    receiver.print(trace);
+    uint16_t code = event.get_value();
+    trace.printf_P(PSTR("code = %hd\n"), code);
+  } 
   receiver.reset();
 }

  TRACE(free_memory());

  // Check size of instances
  TRACE(sizeof(InterruptPin));
  TRACE(sizeof(IRreceiver));


#include "Cosa/Memory.h"

// Enable to allow the IR receiver interrupt handler to collect time periods
#define COLLECT_SAMPLES

class IRreceiver : public InterruptPin, private Link {
private:
  static const uint16_t TIMEOUT = 512;
  static const uint16_t PRE_DATA = 0x20df;
  static const uint8_t PRE_DATA_BITS = 16;
  static const uint8_t SAMPLE_MAX = 40;
