Arduino mega r3 with adafruit motor shield v1

I am using this sketch I found for opening and closing shades. I modified the digital pins with pin 22 to push button to grnd. Pin 30 to limit switch to grnd for blinds open. Pin 40 to limit switch to grnd for blinds closed. I need this to operate 4 blinds independently and have no clue of what to do to make this work. I am in a time crunch and do not have the time to research hooking this up and coding it properly. Any help would be greatly appreciated.


const int activate = 22; //set up our button constants const int gateOpen = 30; const int gateClosed = 40; const int bridgeOneA = 5; const int bridgeTwoA = 6; const int enable = 7; const int statLED = 13;

unsigned long currentTime = 0;

boolean gateState = false; //false = closed true = open

void setup() { Serial.begin(9600); pinMode(activate, INPUT); //set up I/O pinMode(gateOpen, INPUT); pinMode(gateClosed, INPUT); pinMode(bridgeOneA, OUTPUT); pinMode(bridgeTwoA, OUTPUT); pinMode(enable, OUTPUT); digitalWrite(enable, LOW); //make sure H-Bridge is off pinMode(statLED, OUTPUT); //setup our status LED }

void loop() { if (digitalRead(activate) == HIGH && gateState == false) { //check to see if the button is pressed and the gate is closed digitalWrite(enable, HIGH); //enable h-bridge digitalWrite(bridgeOneA, HIGH); //configure for CW rotation digitalWrite(bridgeTwoA, LOW); while(1){ //run motor until switch is tripped if (digitalRead(gateOpen) == LOW) { //check switch state gateState = true; digitalWrite(statLED, LOW); //turn off LED digitalWrite(enable, LOW); //disable h-bridge digitalWrite(bridgeOneA, LOW); //reset h-bridge config break; } if (millis() > currentTime + 500) { //flash status LED once digitalWrite(statLED, HIGH); delay(500); currentTime = millis(); } else { digitalWrite(statLED, LOW); } } } if (digitalRead(activate) == HIGH && gateState == true) { //check to see if the button is pressed and the gate is open digitalWrite(enable, HIGH); digitalWrite(bridgeOneA, LOW); //configure for CCW rotation digitalWrite(bridgeTwoA, HIGH); while(1){ if (digitalRead(gateOpen) == LOW) { gateState = false; digitalWrite(statLED, LOW); digitalWrite(enable, LOW); digitalWrite(bridgeTwoA, LOW); break; } if (millis() > currentTime + 500) { //flash status LED once digitalWrite(statLED, HIGH); delay(500); currentTime = millis(); } else { digitalWrite(statLED, LOW); } } } }