   Serial.begin(9600);
 }
 
-//Check serial buffer for any strings from Matlab and call Corresponding Function
+//Check serial buffer for any strings from RPI and call Corresponding Function
 void loop() {
   if(Serial.available() > 0) { //Check serial buffer if any data available
     serialData = Serial.read(); //read string from serial buffer

  }
}

void hardwareDispense(){
  int bills[4];
  int total = 0;
  for (int i = 0; i<=4; i++){
    while(Serial.available() <= 0){ //wait until Matlab sends voltage on serial buffer
    }
    serialData = Serial.read(); //get the desired count from serial
    bills[i] = char2Int(serialData); //converting serial string into int
    total = total + bills[i];
  }
  //define IR sensor pin as interrupt pin to add one automatically to bills count
  attachInterrupt(digitalPinToInterrupt(infrared), counter, RISING);

  //TODO: Dispense here
  
  //check number of dispensed bills
  if(billCount == total)
    Serial.print("t");
  else if(billCount != total)
    Serial.print("f");
  billCount = 0; //resets billCount
}

void openDoor(){
  digitalWrite(drawer, HIGH);
  delay(doorDelay);

////////////////////////////////////////////////////////////

//Arduino Pins definition
//stepper-1 "up/down" pump
#define    upPin1       2
#define    upPin2       3
#define    upPin3       4
#define    upPin4       5
//stepper-2 "rotation" plate
#define    roPin1       6
#define    roPin2       7
#define    roPin3       8
#define    roPin4       9
//other outputs
#define    drawer       10
#define    warehouse    11
#define    pump         12
//sensors
#define    infrared     13
#define    current      A0
#define    temperature  A1
#define    lightLevel   A2

#define    doorDelay        1000 //time to keep door motor working
#define    warehouseDelay   1000 //time to keep warehouse motor working
#define    releaseBillDelay 1000 //to wait untill bill released
#define    getBillDelay     1000 //to wait until bill catched for sure
#define    upStepperDelay   3    //to wait before up/down steps
#define    roStepperDelay   10   //to wait before rotation steps

#define    currentThreeshold 5    //current where pump gets a bill
#define    currentOffset     2    //offset for current sensor
#define    maxUpSteps        100  //maximum number of steps pump should move
#define    step72            10   //steps required to rotate 72 degrees

//variables definition
char  serialData;             //for storing serial string
float tempFloat       = 0;    //for saving sensor data temporary
int billCount         = 0;    //for storing bill count added by ISR
int selectedWarehouse = 0;    //to know what warehouse is above the door "0 is the empty one"

/// using half step mode
int seq[8][4]={ {1,0,0,0},
                {1,1,0,0},
                {0,1,0,0},
                {0,1,1,0},
                {0,0,1,0},
                {0,0,1,1},
                {0,0,0,1},
                {1,0,0,1} };


void setup() {
  //Setting input/output Pins
  //outputs
  pinMode(  upPin1,     OUTPUT);
  pinMode(  upPin2,     OUTPUT);
  pinMode(  upPin3,     OUTPUT);
  pinMode(  upPin4,     OUTPUT);
  pinMode(  roPin1,     OUTPUT);
  pinMode(  roPin2,     OUTPUT);
  pinMode(  roPin3,     OUTPUT);
  pinMode(  roPin4,     OUTPUT);
  pinMode(  drawer,     OUTPUT);
  pinMode(  warehouse,  OUTPUT);
  pinMode(  pump,       OUTPUT);
  //inputs
  pinMode(  infrared,    INPUT);
  pinMode(  current,     INPUT);
