+
 #include <avr/sleep.h>
 #include <avr/power.h>
 #include <avr/wdt.h>
 #include <SdFat.h>                // SD and RTC libraries
 #include "RTClib.h"
 #include <Wire.h>
-#include <Stepper.h>
 #include <SPI.h>
 #include <Adafruit_GFX.h>
 #include <Adafruit_SharpMem.h>
 #include <avr/interrupt.h>
 #include <avr/io.h>
 #include <SoftwareSerial.h>
+#include <Adafruit_MotorShield.h>
+#include "utility/Adafruit_PWMServoDriver.h"
 
 #define FILENAME "PELLET_Cage12.csv"
 
 #define DISPLAY_SERIAL_RX_PIN 255 // we don't need a receive pin, 255 indicates this
 // Connect the Arduino pin 3 to the rx pin on the 7 segment display
 #define DISPLAY_SERIAL_TX_PIN 9
+
+// Photo interrupter is also the wakeup for the system
+#define PHOTO_INTERRUPTER_PIN 2
 
 SoftwareSerial LEDserial = SoftwareSerial(DISPLAY_SERIAL_RX_PIN, DISPLAY_SERIAL_TX_PIN);
 SdFat SD;

  power_spi_disable();
}

void setMotorToTurn() {
    pinMode(MOTOR_INPUT1_PIN, OUTPUT);
    pinMode(MOTOR_INPUT2_PIN, OUTPUT);
    pinMode(MOTOR_INPUT3_PIN, OUTPUT);
    pinMode(MOTOR_INPUT4_PIN, OUTPUT);

    pinMode(MOTOR_ENABLE12_PIN, OUTPUT);
    pinMode(MOTOR_ENABLE34_PIN, OUTPUT);
    digitalWrite(MOTOR_ENABLE12_PIN, HIGH);
    digitalWrite(MOTOR_ENABLE34_PIN, HIGH);
}

void setMotorToSleep() 
{
    digitalWrite(MOTOR_ENABLE12_PIN, LOW);
    digitalWrite(MOTOR_ENABLE34_PIN, LOW);  

    pinMode(MOTOR_INPUT1_PIN, INPUT_PULLUP);
    pinMode(MOTOR_INPUT2_PIN, INPUT_PULLUP);
    pinMode(MOTOR_INPUT3_PIN, INPUT_PULLUP);
    pinMode(MOTOR_INPUT4_PIN, INPUT_PULLUP);
}

void setup()
{
  // make all unused pins inputs with pullups enabled by default, lowest power drain
  // leave pins 0 & 1 (Arduino RX and TX) as they are
  for (byte i=2; i <= 20; i++) {    

    pelletCount ++;
    Serial.println(F("It did work"));
    clearDisplay();
    delay(2); // allow a very short delay for display response
    setDisplayValues(pelletCount);
    lastState = PIState;
  }
  else if (PIState == 1) {
    Serial.println(F("Turning motor..."));
    power_twi_enable();
    gPtrToStepper->step(STEPS_TO_INCREMENT/2,FORWARD,DOUBLE);
    gPtrToStepper->step(STEPS_TO_INCREMENT,BACKWARD,DOUBLE);
    gPtrToStepper->release();
    power_twi_disable();
    lastState = PIState;
  }
  
