#include <avr/interrupt.h>
#include <avr/sleep.h>

// Set to "1" to enable debug output, 0 (or else) disables serial output
#define DEBUG 1

#if DEBUG == 1
  #define Debugln(x) Serial.println(x)
#else
  #define Debugln(x)
#endif

// Define relay pins 
#define relayPin_1 11
#define relayPin_2 12
#define interval 2000

void setup() {
  Serial.begin(9600);  // open the serial port at 9600 bps

  // Init pins HIGH
  digitalWrite(relayPin_1, HIGH);
  digitalWrite(relayPin_2, HIGH);
  pinMode(relayPin_1, OUTPUT);
  pinMode(relayPin_2, OUTPUT);

  Debugln("Hello!");
}

void loop() {
  delay(interval);  // Wait for 2 seconds
  Debugln("Enable power rail #1");
  digitalWrite(relayPin_1, LOW);  // Poweron relay #1

  delay(interval);
  Debugln("Enable power rail #2");
  digitalWrite(relayPin_2, LOW);  // Poweron relay #2

  delay(50);  // wait for UART to finish
  stop();
}   

void stop() {
  // Turn microcontroller off
  Debugln("All done, powering off. Goodbye.");
  delay(100);  // wait for UART to finish

  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  cli();
  sleep_mode();
}
