Cosa: An Object-Oriented Platform for Arduino programming

guiguid, that is a nice idea! Below is a snippet of an example sketch how to do the monitoring

class VCC : public Periodic {
private:
  uint16_t m_threshold;
  uint16_t m_vcc;
  virtual void run()
  {
    m_vcc = AnalogPin::bandgap();
    if (m_vcc > m_threshold) return;
    on_low_voltage();
  }
public:
  VCC(uint16_t mv, uint16_t ms = 1024) :
    Periodic(ms),
    m_threshold(mv),
    m_vcc(0)
  {}
  virtual void on_low_voltage()
  {
    trace << Watchdog::get_millis() / 1000 << ':' << m_vcc << PSTR(" mV\n");
  }
};

VCC lowPower(4900);

The callback, the virtual function on_low_voltage(), is called when the threshold is exceeded. The default implementation will print the measurement. Sub-class VCC and override the virtual function to implement your own action.

Please see the full the sketch Cosa/CosaVCC.ino at master · mikaelpatel/Cosa · GitHub

In a later update of Cosa I might bring the VCC class into the library.

Cheers!