Interrupt driven pulse counter and sleep mode

This sketch detects pulses and prints the character P to the serial port.

In order to reduce power consumption, the Atmega 328 is put into sleep mode between pulses. The interrupt pulse input (digital input pin 2 or 3) is used to wake the device.

Unfortunately a power value can't be calculated as the timers do not run in sleep mode.

Kudos to Donal Morrissey for his clear tutorial on Arduino sleep mode: Sleeping Arduino

#include <avr/sleep.h>

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

void setup()
  /* Setup the interrupt pin */
  attachInterrupt(1, onPulse, FALLING);
  cbi( SMCR,SE );      // sleep enable, power down mode
  cbi( SMCR,SM0 );     // power down mode
  sbi( SMCR,SM1 );     // power down mode
  cbi( SMCR,SM2 );     // power down mode

void loop()
  // 1) Enter sleep mode
  //cbi(ADCSRA,ADEN);    // switch Analog to Digital converter OFF

  // The arduino is now sleeping...
  // 2) Program will resume from here on interrupt
  sbi(ADCSRA,ADEN);    // switch Analog to Digitalconverter ON

void onPulse()
  // It continues in the main loop