 
 void forwardstep() { 
   baseShield.setMePort(portNo, LOW, HIGH);
-  delayMicroseconds( pulseLength );
+  delayMicroseconds( MOVE_ITEM_STEPPER_PULSE_LENGTH );
   baseShield.setMePort(portNo, HIGH, HIGH);
-  delayMicroseconds( pulseLength );
+  delayMicroseconds( MOVE_ITEM_STEPPER_PULSE_LENGTH );
   baseShield.setMePort(portNo, HIGH, LOW);
-  delayMicroseconds( pulseLength );
+  delayMicroseconds( MOVE_ITEM_STEPPER_PULSE_LENGTH );
   baseShield.setMePort(portNo, LOW, LOW);
-  delayMicroseconds( pulseLength );
+  delayMicroseconds( MOVE_ITEM_STEPPER_PULSE_LENGTH );
 }
 void backwardstep() { 
   baseShield.setMePort(portNo, LOW, LOW);
-  delayMicroseconds( pulseLength );
+  delayMicroseconds( MOVE_ITEM_STEPPER_PULSE_LENGTH );
   baseShield.setMePort(portNo, HIGH, LOW);
-  delayMicroseconds( pulseLength );
+  delayMicroseconds( MOVE_ITEM_STEPPER_PULSE_LENGTH );
   baseShield.setMePort(portNo, HIGH, HIGH);
-  delayMicroseconds( pulseLength );
+  delayMicroseconds( MOVE_ITEM_STEPPER_PULSE_LENGTH );
   baseShield.setMePort(portNo, LOW, HIGH);
-  delayMicroseconds( pulseLength );
-}
+  delayMicroseconds( MOVE_ITEM_STEPPER_PULSE_LENGTH );
+}

#include <Me_BaseShield.h>
#include <Me_InfraredReceiver.h>
#include <Me_UltrasonicSensor.h>
#include "MakeblockStepper.h"


int fsmState;

/* Hardware components */
Me_BaseShield baseShield;
Me_InfraredReceiver infraredReceiver; /* Note: As the code need to use interrupt 0, it works only when the Me - Infrared Receiver module is connected to the port 4(PORT_4) of Me - Base Shield. */
Me_UltrasonicSensor ultraSensor( PORT_5 ); //Ultrasonic module can ONLY be connected to port 3, 4, 5, 6, 7, 8 of base shield. ultraSensor.distanceCm()
// MakeblockStepper moveItemStepper( 3200, baseShield, PORT_3 );
Me_ServoDriver servoDriver( PORT_1 ); //can ONLY be PORT_1,PORT_2
Me_BaseShieldMotorDriver baseShieldMotorDriver;

/* Flapping servo */
int SERVO1_UP = 133;
int SERVO1_DOWN = 110;
int lowerTopFlapDelay = 200;

/* Move item stepper */
int portNo = PORT_3;
AccelStepper moveItemStepper( forwardstep, backwardstep );
int MOVE_ITEM_STEPPER_PULSE_LENGTH = 30;
float MOVE_ITEM_STEPPER_MAX_SPEED = 2500.0;
float MOVE_ITEM_IN_MAX_SPEED = 2500.0;
float PULL_BACK_FLAP_MAX_SPEED = 2000.0;
float MOVE_ITEM_OUT_STEPPER_MAX_SPEED = 2500.0;
float MOVE_ITEM_STEPPER_ACCELERATION = 30000.0;
int MOVE_ITEM_IN_STEPS = 10000;
int PULL_BACK_FLAP_STEPS = 600;
int MOVE_ITEM_OUT_STEPS = 650;
boolean moveItemStepperIsRunning = false;

/* Solenoid contact servo */
int CONTACT_OFF_POSITION = 140;
int CONTACT_ON_POSITION = 180;

/* Output conveyor motor */
int OUTPUT_CONVEYANCE_SPEED = -190;
int OUTPUT_CONVEYANCE_DURATION = 155;

void setup() {
  // Initailize FSM
