#include #include #include #include #include "C:\Program Files\Arduino\Settings.h" #include #include Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield(); //LiquidCrystal lcd(8, 9, 4, 5, 6, 7); #define RED 0x1 // These #defines make it easy to set the backlight color #define YELLOW 0x3 #define GREEN 0x2 #define TEAL 0x6 #define BLUE 0x4 #define VIOLET 0x5 #define WHITE 0x7 #define EN1_PIN 3 // Set up for Main Stepper Motor #define EN2_PIN 11 #define DIR1_PIN 12 #define DIR2_PIN 13 #define stepPin 23 //43 // 22 New set up for second motor #define dirPin 25 //45 // 24 #define enablePin 27 //47 // 26 #define foodPumpMotorPin 28 // Setting up peristaltic pump for liquid food #define waterPumpMotorPin 29 // Setting up peristaltic pump for water replacement #define stepsPerRevolution 200 // Change this to fit the number of steps per revolution for main stepper #define ledPin 27 // I DON'T KNOW IF THIS IS NOT USED AND GOOD FOR LED! #define optOutPin1 48 // 51On Start Up sencer Anode (1), Cathode (2) Ground #define optInPin1 49 // 53Collector (3), Emitter (4) Ground #define optOutPin2 50 // 51All Stop Sensor Anode (1) 52, Cathode (2) Ground #define optInPin2 52 // 53Collector (3), Emitter (4) Ground #define optOutPin3 51 // 50Boom Up Anode (1) 52, Cathode (2) Ground #define optInPin3 53 // 52Collector (3), Emitter (4) Ground int Relay[8] = {28, 30, 32, 34, 29, 31, 33, 35}; int raiseTheBoomSteps = 620; int lowerTheBoomSteps = 620; int stepsToNextStation; // Set initial default values int maxRPM = 150; // Top running speed of main stepper int PWM = 255; int DIR = 1; int totalSteps = 0; // Only for degugging int location = 0; int distplayDigits; int stationCount = 6; // The number of pins (i.e. the length of the array) int fullSpeed = 0; // Flag goes to 1 when full speed is reached int upCount = 0; long lastDebounceTime = 0; long debounceDelay = 200; int i; int in; int keyTime = 0; int tempLocationSet = 0; int xLocation; int yLocation; int tempLocation; int manualStepsToNextStation; int inputDigitCount = 0; int numKeyPressed = 0; long distance[6]={d_val}; // #define d_val 11, 21, 31, 41, 51, 61 Moved to setting.l file above long fTime[6]={f_val}; // #define f_val 12, 22, 32, 42, 52, 62 Moved to setting.l file above long wTime[6]={w_val}; // #define w_val 13, 23, 33, 43, 53, 63 Moved to setting.l file above long interval = 300; // interval at which to blink (milliseconds) long previousMillis = 0; // will store last time LED was updated long delayBetweenStations = 10000; //long delayBetweenStations = 1000L * 60 * 10; // Time to wait before moving to next station unsigned long t_hold; char key; char key2; // (1/1000 sec. times 60)=1 minute, times 10= 10 minutes char holdKey; String getDistance; bool keypressed = false; // can't use 0 1 2 3 4 5 6 enum menuLevel { UNDEF, mainMenu, autoMenu, manualMenu, manualStepMenu, makeDistanceMenu, keyCheckMenu }; char instructions[] = { " Enter Number of Steps. Then Press < or > to START " }; char scrollstring[17] = { '\0' }; const byte ROWS = 4; //four rows // Setup LCD const byte COLS = 4; //four columns // Setup LCD ; char keys[ROWS][COLS] = { {'1','2','3','A'}, {'4','5','6','B'}, {'7','8','9','C'}, {'*','0','#','D'} }; byte rowPins[ROWS] = {45, 43, 41, 39}; //connect to the row pinouts of the keypad 37, 35, 33, 31 // Setup LCD byte colPins[COLS] = {37, 35, 33, 31}; //connect to the column pinouts of the keypad // Setup LCD Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); Stepper stepper(stepsPerRevolution, DIR1_PIN, DIR2_PIN); // Number of steps per revolution menuLevel menL = mainMenu; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< SET UP LOOP >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void setup() { Serial.begin(9600); // initialize the// Serial port lcd.setBacklight(WHITE); // pinMode(optOutPin1, OUTPUT); // set pin to output for optical sensor 1 // pinMode(optInPin1, INPUT); // set pin to input for optical sensor 1 // pinMode(optOutPin2, OUTPUT); // set pin to output for optical sensor 2 // pinMode(optInPin2, INPUT); // set pin to input for optical sensor 2 // pinMode(optOutPin3, OUTPUT); // set pin to output for optical sensor 3 // pinMode(optInPin3, INPUT); // set pin to input for optical sensor 3 pinMode(optOutPin1, OUTPUT); pinMode(optInPin1, INPUT); // set pin to input pinMode(optOutPin2, OUTPUT); pinMode(optInPin2, INPUT); // set pin to input pinMode(optOutPin3, OUTPUT); pinMode(optInPin3, INPUT); // set pin to input pinMode(EN1_PIN, OUTPUT); digitalWrite(EN1_PIN, LOW); pinMode(EN2_PIN, OUTPUT); digitalWrite(EN2_PIN, LOW); pinMode(DIR1_PIN, OUTPUT); digitalWrite(DIR1_PIN, LOW); pinMode(DIR2_PIN, OUTPUT); digitalWrite(DIR2_PIN, LOW); TCCR2B = _BV(CS21); // Change from x/64 prescale, Timer 2 to x/8 to get 8 * faster PWM(976 Hz --> 7.8 kHz). This should prevent // This should prevent overcurrent conditions for steppers with high voltages and low inductance. analogWrite(EN1_PIN, PWM); //Now enable PWM and start motion analogWrite(EN2_PIN, PWM); stepper.setSpeed(maxRPM); //Setting up the Pololu Stepper Motor //pinMode(enablePin, OUTPUT); //digitalWrite(enablePin, HIGH); pinMode(stepPin, OUTPUT); pinMode(dirPin, OUTPUT); int stationNumber; int stationReadOut; pinMode(ledPin, OUTPUT); // Set up the LED pin: blink(3); // blink the LED; lcd.clear(); lcd.begin(16, 2); // Define an array for the LCD } // xxxxxxxxxxxxxxxxxxxxxxxxx End of Set Up Loop xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< * VOID LOOP * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void loop() { clearLCD(); lcd.setBacklight(TEAL); lcd.setCursor(0,0); lcd.print("Press # to enter"); lcd.setCursor(0,1); lcd.println(" Manual Mode "); Serial.println(String("BEGIN keyTime is ") + int(keyTime) + String(" before key 'for' loop")); while(keyTime <= 3000) { //Serial.println(String("Read ") + int(keyTime) + String(" inside key 'for' loop")); keyPadFunction(); //Serial.println("returned from keyPadF"); delay(5); keyTime = keyTime + 1; } keyTime = 0; clearLCD(); Serial.println("Left 'for' to keyPadF"); digitalWrite(optOutPin1,HIGH); // Turn on pin for Home senser digitalWrite(optInPin1,HIGH); // Turn on pullup resistors digitalWrite(optOutPin2,HIGH); // Turn on pin for All Stop Sensor digitalWrite(optInPin2,HIGH); // Turn on pullup resistors digitalWrite(optOutPin3,HIGH); // Turn on pin for Boom Up senser digitalWrite(optInPin3,HIGH); // Turn on pullup resistors //opticalSensor1 = digitalRead(optOutPin1); Serial.println("Pre-Start UP"); lcd.setBacklight(TEAL); onStartUp(); //<<************************ // Re-set the system when it starts or re-starts lcd.setBacklight(WHITE); //lcd.clear(); lcd.setCursor(9,0); lcd.print(" "); lcd.setCursor(9,1); lcd.print(" "); int stationReadOut; // Added so that stationNumber will read correctly for (int stationNumber = 0; stationNumber < stationCount; stationNumber++) { stationReadOut = stationNumber + 1; const int stepsToNextStation = distance[stationNumber]; const int timeForFoodPumping = fTime[stationNumber]; const int timeForWaterPumping = wTime[stationNumber]; lcd.setCursor(0,0); // Upper row (0), character 1 (0) lcd.print("Station:"); lcd.print(stationReadOut); raiseTheBoom; boomCheck(); lcd.setBacklight(GREEN); moveToNextStation(stepsToNextStation, DIR); lcd.setBacklight(WHITE); lcd.setCursor(9, 1); lcd.print(totalSteps); extendAndFeed(timeForFoodPumping,timeForWaterPumping); } goHome(); } // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx *Void Loop* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Move To Next Station >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void moveToNextStation(int stepsToNextStation, int DIR) { Serial.println("Start"); // Serial.println(DIR); Serial.println(String("Inside 'move', Read step number to be ") + int(stepsToNextStation) + String(" and DIR is ") + int(DIR)); int opticalSensor1; int opticalSensor2; int opticalSensor3; int startSlowing = stepsToNextStation - 60; int fullSpeed = 0; int currentSpeed = 0; int time = 0; int distplayDigits = 0; int start; int finished; int elapsed; long lastDebounceTime = 0; long debounceDelay = 200; distplayDigits = stepsToNextStation; // start=millis(); digitalWrite(optOutPin1, HIGH); digitalWrite(optInPin1, HIGH); // turn on pullup resistors digitalWrite(optOutPin2, HIGH); digitalWrite(optInPin2, HIGH); // turn on pullup resistors digitalWrite(optOutPin3, HIGH); digitalWrite(optInPin3, HIGH); // turn on pullup resistors if ( stepsToNextStation <= 61 ) { justCrawl(stepsToNextStation, DIR); // Serial.println("Back From Crawling"); } else { // Serial.println("Back else"); for (int i=1; i <= startSlowing; i++) // Loops until it reaches the next station count. { // keyPadFunction(); opticalSensor1 = digitalRead(optInPin1); // turn on pullup resistors opticalSensor2 = digitalRead(optInPin2); // turn on pullup resistors opticalSensor3 = digitalRead(optInPin3); // turn on pullup resistors // Serial.println("Inside of 'move' 'for'"); // Serial.println("Sensor3"); char key = keypad.getKey(); if (key) { in = key; if (in == '*') { allStop(); } } if (opticalSensor1 == HIGH) //&& (lastDebounceTime > debounceDelay) { // Serial.println("All Stop"); break; } if (currentSpeed <= maxRPM && fullSpeed <= 1 ) // If current speed raises to full and { // it hasn't alread reach it, then if (currentSpeed <= maxRPM-1) // If current speed is less than maxRPM { currentSpeed = currentSpeed + 1; // add one to speed it up } else { fullSpeed = 1; // else flag as full speed reached //Serial.println(maxRPM); //Serial.println(totalSteps); } } if (opticalSensor3 == HIGH ) // { allStop(); // } stepper.setSpeed(currentSpeed);// Set speed analogWrite(EN1_PIN, PWM); // Do the stepping PIN1 analogWrite(EN2_PIN, PWM); // Do the stepping PIN2 stepper.step(DIR); // This is a busy-wait loop until the inter-step time passes totalSteps = totalSteps + 1; // For debugging location = totalSteps; if (DIR == -1) { distplayDigits = distplayDigits - 1; LCDrightJustifiedNumbers(distplayDigits); } else { LCDNumberTotalSteps(totalSteps); } // Serial.println(i); // Serial.println(totalSteps); } // Serial.println("Pass"); for (int j=59; j >= 0; --j) // Decelerate Loop until stop point is reached { // Serial.println(j); // Serial.println(currentSpeed); // opticalSensor2 = digitalRead(optInPin2); // turn on pullup resistors if (opticalSensor3 == LOW){allStop();} // Change to HIGH when installed!// If Home Sensor in blocked do a restart if (currentSpeed >= 5) { currentSpeed = currentSpeed - 2; // Subtract one } stepper.setSpeed(currentSpeed); // Set speed analogWrite(EN1_PIN, PWM); // Do the stepping analogWrite(EN2_PIN, PWM); // Do the stepping stepper.step(DIR); // This is a busy-wait loop until the inter-step time passes totalSteps = totalSteps + 1; location = totalSteps; if (DIR == -1) { // Serial.println(DIR); distplayDigits = distplayDigits - 1; LCDrightJustifiedNumbers(distplayDigits); } else { // Serial.println(DIR); LCDNumberTotalSteps(totalSteps); //Serial.println(totalSteps); } LCDNumberTotalSteps(totalSteps); } } analogWrite(EN1_PIN, 0); analogWrite(EN2_PIN, 0); Serial.println("Going Back"); } //xxxxxxxxxxxxxxxxxxxxxxx End of Move to Next Station xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< RAISE THE FEEDING BOOM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void raiseTheBoom() { lcd.setBacklight(YELLOW); int j; int accelerate = 5000; digitalWrite(enablePin, LOW); delayMicroseconds(2); digitalWrite(dirPin, LOW); // we set the direction pin in an arbitrary direction. Serial.println("Boom Up"); for(j=0; j<=raiseTheBoomSteps; j++) { digitalWrite(stepPin, LOW); delayMicroseconds(2); digitalWrite(stepPin, HIGH); delayMicroseconds(accelerate); if(accelerate >= 1024) { accelerate = (accelerate - (accelerate/199)); } } } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Raise The Feeding Boom xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< LOWER THE FEEDING BOOM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void lowerTheBoom() { lcd.setBacklight(YELLOW); Serial.println("Boom Down"); int j; int decelerate = 5000; delayMicroseconds(2); digitalWrite(dirPin, HIGH); // we set the direction pin in an arbitrary direction. for(j=0; j<=lowerTheBoomSteps; j++) { digitalWrite(stepPin, LOW); delayMicroseconds(2); digitalWrite(stepPin, HIGH); delayMicroseconds(decelerate); if(decelerate >= 1024) { decelerate = (decelerate - (decelerate/199)); } // delay(100) // digitalWrite(enablePin, HIGH); // Turn off power to the Boom Stepper Motor. } } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Lower The Feeding Boom xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // XXXXXXXXXXXXXXXXXXXXXXXXXXX EXTENT, FEED AND CHANGE WATER XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX void extendAndFeed(int timeForFoodPumping, int timeForWaterPumping) { if (timeForFoodPumping == 0 && timeForWaterPumping == 0) // If no pumping is assigned, skip to next tower { lcd.setCursor(0,1); // Upper row (0), character 1 (0) lcd.print("Y:SKIP "); return; // Go back, skip } delay(100); // Wait a about second lcd.setCursor(0,1); // Upper row (0), character 1 (0) lcd.print("Y:DOWN "); lowerTheBoom(); digitalWrite(enablePin, HIGH); // Turn off motor // digitalWrite(stepPin, LOW); digitalWrite(dirPin, HIGH); // raiseTheBoom(); delay(100); // Wait a about second lcd.setBacklight(GREEN); lcd.setCursor(0,1); // Upper row (0), character 1 (0) lcd.print("FEEDING "); digitalWrite(foodPumpMotorPin, HIGH); // Turn on food pump delay(timeForFoodPumping); // Wait "timeForFoodPumping" amount of time digitalWrite(foodPumpMotorPin, LOW); // Turn off food pump Serial.println("Food Pump Motor LED On?"); delay(1000); // Wait a about second lcd.setBacklight(BLUE); lcd.setCursor(0,1); // Upper row (0), character 1 (0) lcd.print("WATER ON"); digitalWrite(waterPumpMotorPin, HIGH); // Turn on water pump delay(timeForWaterPumping); // Wait "timeForWaterPumping" amount of time digitalWrite(waterPumpMotorPin, LOW); // Turn off water pump Serial.println("Food Pump Motor LED Off"); delay(1000); // Wait a about second digitalWrite(dirPin, LOW); lcd.setCursor(0,1); // Upper row (0), character 1 (0) lcd.print("Y:UP "); digitalWrite(enablePin, LOW); // Turn on motor raiseTheBoom(); delay(100); lcd.setBacklight(WHITE); } // xxxxxxxxxxxxxxxxxxxxxxxx End of Move To Station xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< LCD Total Steps DISPLAY >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void LCDNumberTotalSteps(int totalSteps) { unsigned long currentMillis = millis(); if(currentMillis - previousMillis > interval) { previousMillis = currentMillis; lcd.setCursor(9,1); // Upper row (0), character 1 (0) lcd.print(totalSteps); } } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx LCD Total Steps Display xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< LCD RIGHT JUSTIFIED NUMBER DISPLAY >>>>>>>>>>>>>>>>>>>>>>>>>> void LCDrightJustifiedNumbers(int distplayDigits) { unsigned long currentMillis = millis(); if(currentMillis - previousMillis > interval) { previousMillis = currentMillis; if (distplayDigits < 10000) { lcd.setCursor(9,1); lcd.print(" "); lcd.setCursor(10,1); } if (distplayDigits < 1000) { lcd.setCursor(9,1 ); lcd.print(" "); lcd.setCursor(11,1); } if (distplayDigits < 100) { lcd.setCursor(9,1); lcd.print(" "); lcd.setCursor(12,1); } if (distplayDigits < 10) { lcd.setCursor(9,1); lcd.print(" "); lcd.setCursor(13,1); } lcd.print(distplayDigits); } } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx LCD Number distplayDigits Display xxxxxxxxxxxxxxxxxxxxxxxx // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GO BACK HOME >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void goHome() { lcd.setBacklight(YELLOW); long distanceToHome = 0; distanceToHome = distance[0] + distance[1] + distance[2] + distance[3] + distance[4] +distance[5] -13; stepsToNextStation = distanceToHome; lcd.setCursor(8,0); // Upper row (0), character 1 (0) lcd.print(" Go Home"); DIR = -1; Serial.println("Go Home"); easeHome(stepsToNextStation, DIR); analogWrite(EN1_PIN, 0); analogWrite(EN2_PIN, 0); DIR = 1; lcd.setCursor(8,0); // Upper row (0), character 1 (0) lcd.setBacklight(RED); lcd.print("Home"); delay(20); lcd.setBacklight(TEAL); if (distplayDigits < 10000) { lcd.setCursor(9,1); } if (distplayDigits < 1000) { lcd.setCursor(9,1 ); lcd.print(" "); lcd.setCursor(10,1); } if (distplayDigits < 100) { lcd.setCursor(9,1); lcd.print(" "); lcd.setCursor(11,1); } if (distplayDigits < 10) { lcd.setCursor(9,1); lcd.print(" "); lcd.setCursor(12,1); } lcd.print(distplayDigits); lcd.setBacklight(RED); // lowerTheBoom(); lcd.setBacklight(BLUE); delay(50); digitalWrite(enablePin, HIGH); // Turn off power to the Boom Stepper Motor. delay(delayBetweenStations); // Time to wait before moving to next station //Serial.println(distanceToHome); //Serial.println(stepsToNextStation); lcd.clear(); stepsToNextStation = 0; totalSteps = 0; distplayDigits = 0; digitalWrite(enablePin, LOW); } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx End of Go Back Home xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EASE HOME >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void easeHome(int stepsToNextStation, int DIR) { lcd.setBacklight(VIOLET); Serial.println("Start Going Home"); // Serial.println(DIR); Serial.println(stepsToNextStation); { int opticalSensor1; int opticalSensor2; int opticalSensor3; int startSlowing = stepsToNextStation - 100; int fullSpeed = 0; int currentSpeed = 0; int time = 0; int distplayDigits = 0; distplayDigits = stepsToNextStation; long lastDebounceTime = 0; long debounceDelay = 200; digitalWrite(optOutPin1, HIGH); digitalWrite(optInPin1, HIGH); // turn on pullup resistors digitalWrite(optOutPin2, HIGH); digitalWrite(optInPin2, HIGH); // turn on pullup resistors digitalWrite(optOutPin3, HIGH); digitalWrite(optInPin3, HIGH); // turn on pullup resistors Serial.println("Look to move back"); for (int i=1; i <= startSlowing; i++) // Loops until it reaches the next station count. { opticalSensor1 = digitalRead(optInPin1); // turn on pullup resistors boomCheck(); opticalSensor3 = digitalRead(optInPin3); // turn on pullup resistors if (opticalSensor1 == HIGH) //&& (lastDebounceTime > debounceDelay) { Serial.println("Sensor 1 HIGH"); break; } else { Serial.println("Sensor didn't Read"); } char key = keypad.getKey(); if (key) { in = key; if (in == '*') { allStop(); } } if (currentSpeed <= maxRPM && fullSpeed <= 1 ) // If current speed raises to full and { // it hasn't alread reach it, then if (currentSpeed <= maxRPM-1) // If current speed is less than maxRPM { currentSpeed = currentSpeed + 1; // add one to speed it up } else { fullSpeed = 1; // else flag as full speed reached //Serial.println(maxRPM); //Serial.println(totalSteps); } } stepper.setSpeed(currentSpeed);// Set speed analogWrite(EN1_PIN, PWM); // Do the stepping PIN1 analogWrite(EN2_PIN, PWM); // Do the stepping PIN2 stepper.step(DIR); // This is a busy-wait loop until the inter-step time passes totalSteps = totalSteps + 1; // For debugging location = totalSteps; // Serial.println(String("location ") + (location) + String("totalSteps") + (totalSteps)); if (DIR == -1) { distplayDigits = distplayDigits - 1; LCDrightJustifiedNumbers(distplayDigits); // Serial.println(String("distplayDigits") + (distplayDigits)); } else { LCDNumberTotalSteps(totalSteps); // Serial.println(String("distplayDigits") + (distplayDigits)); } // Serial.println(i); // Serial.println(totalSteps); } // Serial.println("Pass"); for (int j=299; j >= 0; --j) // Decelerate Loop until stop point is reached { opticalSensor1 = digitalRead(optInPin1); // turn on pullup resistors boomCheck(); opticalSensor3 = digitalRead(optInPin3); // turn on pullup resistors if (opticalSensor1 == HIGH) //&& (lastDebounceTime > debounceDelay) { // Serial.println("All Stop"); Serial.println("Sensor 1 HIGH"); return; } else { Serial.println("Sensor Didn't Read 2"); } char key = keypad.getKey(); if (key) { in = key; if (in == '*') { allStop(); } } if (currentSpeed >= 5) { currentSpeed = currentSpeed - 2; // Subtract one } digitalWrite(optOutPin1, HIGH); digitalWrite(optInPin1, HIGH); // turn on pullup resistors opticalSensor1 = digitalRead(optInPin1); // turn on pullup resistors if (opticalSensor1 == HIGH) { opticalSensor1 = digitalRead(optInPin1); // turn on pullup resistors opticalSensor2 = digitalRead(optInPin2); // turn on pullup resistors opticalSensor3 = digitalRead(optInPin3); // turn on pullup resistors Serial.println("Sensor 1 HIGH"); Serial.println("BREAK at HOME"); break; } stepper.setSpeed(currentSpeed); // Set speed analogWrite(EN1_PIN, PWM); // Do the stepping analogWrite(EN2_PIN, PWM); // Do the stepping stepper.step(DIR); // This is a busy-wait loop until the inter-step time passes totalSteps = totalSteps + 1; location = totalSteps; // Serial.println(String("Location") + (location)); if (DIR == -1) { // Serial.println(DIR); distplayDigits = distplayDigits - 1; LCDrightJustifiedNumbers(distplayDigits); // Serial.println(String("location") + (location)); } else { // Serial.println(DIR); LCDNumberTotalSteps(totalSteps); // Serial.println(String("location") + (location)); //Serial.println(totalSteps); } //Serial.println(currentSpeed); } //digitalWrite(enablePin, HIGH); // Turn off power to the Boom Stepper Motor. lowerTheBoom(); analogWrite(EN1_PIN, 0); analogWrite(EN2_PIN, 0); digitalWrite(enablePin, HIGH); // Turn off power to the Boom Stepper Motor. } LCDNumberTotalSteps(totalSteps); Serial.println("Going Back"); //delay(100000); } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx End of Ease Home xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< onStartUp >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void onStartUp() { LEDLoop(); // Serial.println("LED Loop(ed)"); raiseTheBoom(); boomCheck(); DIR = -1; goHome(); clearLCD(); lcd.setBacklight(TEAL); stepsToNextStation = 0; // Created a Var that acts like TotalSteps but does not report totals. int fakeTotalSteps = 0; int crawlDistance = 10; int crawlBackDistance = 30; int crawlSpeed = 1; int opticalSensor1; int opticalSensor2; // int totalStepsNegative = 0; Serial.println("Calibrating"); lcd.setCursor(0,0); // Upper row (0), character 1 (0) lcd.print("Calibrating:"); lcd.setCursor(0,1); // Upper row (0), character 1 (0) lcd.print("Y:UP "); distplayDigits = 0; digitalWrite(optOutPin1, HIGH); digitalWrite(optInPin1, HIGH); // turn on pullup resistors opticalSensor1 = digitalRead(optInPin1); // turn on pullup resistors // Serial.println(opticalSensor1); delay(1000); for (int i=1; i <= crawlDistance; i++) // Loops until it reaches the crawlDistance count. Away from sensor { // opticalSensor2 = digitalRead(optInPin2); // turn on pullup resistors for All Stop sensor // if (opticalSensor2 == LOW) // !!SET TO HIGH when sencor is installed!! // { // allStop(); // } DIR = 1; stepper.setSpeed(crawlSpeed); // Set speed analogWrite(EN1_PIN, PWM); // Do the stepping PIN1 analogWrite(EN2_PIN, PWM); // Do the stepping PIN2 stepper.step(DIR); // This is a busy-wait loop until the inter-step time passes fakeTotalSteps = fakeTotalSteps + 1; // For debugging location = fakeTotalSteps; lcd.setCursor(9, 1); lcd.print(fakeTotalSteps); // Serial.println(fakeTotalSteps); } opticalSensor1 = digitalRead(optInPin1); // Serial.println(opticalSensor1); delay(500); // Serial.println("Check Output"); lcd.setCursor(9, 1); lcd.print(" "); delay(500); // Serial.println("********"); lcd.setCursor(9, 1); lcd.print(fakeTotalSteps); delay(500); lcd.setCursor(9, 1); lcd.print(" "); for (int j=crawlBackDistance; 1 <= j; j--) // Loops until it reaches the crawlDistance count. way from sensor { digitalWrite(optOutPin1, HIGH); digitalWrite(optInPin1, HIGH); // turn on pullup resistors opticalSensor1 = digitalRead(optInPin1); // turn on pullup resistors if (opticalSensor1 == 1 ) { lcd.setBacklight(RED); delay(10); Serial.println("BREAK!"); lcd.setCursor(0, 1); lcd.print(" "); lcd.setCursor(0, 1); lcd.print(" HOME"); delay(30); lcd.setBacklight(TEAL); // totalSteps = 0; // location = totalSteps; // LCDNumberTotalSteps(totalSteps); delay(1000); lcd.setCursor(0, 1); lcd.print(" "); break; } DIR = -1; stepper.setSpeed(crawlSpeed); // Set speed analogWrite(EN1_PIN, PWM); // Do the stepping PIN1 analogWrite(EN2_PIN, PWM); // Do the stepping PIN2 stepper.step(DIR); // This is a busy-wait loop until the inter-step time passes fakeTotalSteps = fakeTotalSteps - 1; // For debugging location = fakeTotalSteps; lcd.setCursor(9, 1); lcd.print(fakeTotalSteps); // Serial.println(fakeTotalSteps); } lcd.setCursor(9, 1); lcd.print("0 "); delay(500); lcd.setCursor(0, 1); lcd.print(" Home"); delay(1000); lcd.setCursor(0, 1); lcd.setBacklight(GREEN); lcd.print(" Pass"); delay(250); lcd.setBacklight(WHITE); delay(250); lcd.setBacklight(GREEN); delay(250); lcd.setBacklight(WHITE); delay(250); lcd.setBacklight(GREEN); delay(250); lcd.setBacklight(WHITE); delay(250); lcd.setBacklight(GREEN); delay(250); lcd.setBacklight(WHITE); delay(250); lcd.setBacklight(GREEN); delay(1000); lcd.setCursor(0, 1); lcd.print(" START"); delay(1000); Serial.println("Pass"); delay(1000); lcd.clear(); Serial.println("Done OnStart"); DIR = 1; } // xxxxxxxxxxxxxxxxxxxxxxxxxxxx End of On Start Up xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< BOOM CHECK >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void boomCheck() { lcd.setBacklight(RED); int opticalSensor2; int h; digitalWrite(optOutPin2,HIGH); digitalWrite(optInPin2, HIGH); // turn on pullup resistors Serial.println("Boom Check"); opticalSensor2 = digitalRead(optInPin2); // turn on pullup resistors // Serial.println(opticalSensor2); // Serial.println("Sensor2"); if (opticalSensor2 == LOW) // Check to see if Boom is all the way UP. { Serial.println("Boom is LOW"); for(h=0; h<=60; h++) // Try to raise it slowly. { opticalSensor2 = digitalRead(optInPin2); if (opticalSensor2 == LOW) // Check to see if Boom is all the way UP. { digitalWrite(stepPin, LOW); delayMicroseconds(2); digitalWrite(stepPin, HIGH); Serial.println("UP"); Serial.println(h); delay(100); } else { } } } if (opticalSensor2 == HIGH) // Check to see if Boom is all the way UP. { lcd.setBacklight(GREEN); Serial.println("Boom is UP"); } else { Serial.println("Boom is >! NOT !< UP"); allStop(); // If not, All Stop so that Boom in down position } // does not crash into towers as it moves. } // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Boom Check xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< BOOM UP ONE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void boomUpOne() { int opticalSensor2; // int h; digitalWrite(optOutPin2,HIGH); digitalWrite(optInPin2, HIGH); // turn on pullup resistors Serial.println("Boom ONE Up"); opticalSensor2 = digitalRead(optInPin2); // turn on pullup resistors // Serial.println(opticalSensor2); // Serial.println("Sensor2"); if (opticalSensor2 == LOW) // Check to see if Boom is all the way UP. { Serial.println("Boom Up One"); digitalWrite(stepPin, LOW); delayMicroseconds(2); digitalWrite(stepPin, HIGH); Serial.println("UP"); lcd.setBacklight(GREEN); delay(10); lcd.setBacklight(WHITE); } } // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Boom Up One xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< All Stop >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void allStop() // If Sensor 2 tripped shut down main motor { lcd.setBacklight(RED); Serial.println("All Stop"); analogWrite(EN1_PIN, 0); // Turn off main motor analogWrite(EN2_PIN, 0); // Turn off main motor DIR = 1; // Set main motor to forward motion lcd.clear(); lcd.setCursor(0,0); // Upper row (0), character 1 (0) lcd.print("ALL STOP! Press"); lcd.setCursor(0,1); // Upper row (0), character 1 (0) lcd.print("'#' to Re-Start"); digitalWrite(enablePin, HIGH); // Turn off power to Boom Stepper Motor Serial.println("Boom DOWN and OFF"); while(1) { char key = keypad.getKey(); if (key) { in = key; if (in == '#') { keyTime = 0; loop(); } } } } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx All Stop xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< LED LOOP (NOT USED)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void LEDLoop() // If Sensor 2 tripped shut down main motor { int m ; for (m=0;m <8; m++) { digitalWrite(Relay[m], HIGH); //Turn off relay delay(25); } delay(500); for (m=8;m >=0; --m) { digitalWrite(Relay[m], LOW); //Turn off relay delay(25); } delay(1000); for (m=0;m <8; m++) { digitalWrite(Relay[m], HIGH); //Turn off relay delay(250); digitalWrite(Relay[m], LOW); //Turn on relay delay(250); } for (m=0;m <8; m++) { digitalWrite(Relay[m], HIGH); //Turn off relay delay(0); } delay(500); for (m=8;m >=0; --m) { digitalWrite(Relay[m], LOW); //Turn off relay delay(0); } delay(1000); } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Led Loop (NOT USED)xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< BLINK THE RESET LED (NOT USED)>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void blink(int howManyTimes) { int i; for (i=0; i< howManyTimes; i++) { digitalWrite(ledPin, HIGH); delay(200); digitalWrite(ledPin, LOW); delay(200); } } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< BLINK THE RESET LED (NOT USED)>>>>>>>>>>>>>>>>>>>>>>>>>>> void keyPadFunction() { //while(1) // { char key = keypad.getKey(); if (key) { in = key; keyTime = -9000; Serial.println(String("menL ") + int(menL) + String(" After getkey")); if ( in >='0' && in <='9' && menL == keyCheckMenu) { Serial.println("key 'if' is Satisfied"); Serial.println(String("key read 'in' to be ") +int(in) + String(" inside key 'if'")); Serial.println(int(menL) + String(" inside key 'if'")); keypressed = true; Serial.println(String("keypresses T-F ") + int(keypressed) + String(" inside key 'if'")); if(tempLocation == 0) { tempLocation = totalSteps; tempLocationSet = 1; Serial.println(String("tempLocation is set to ") + int(tempLocationSet)); } Serial.println(String("set tempSteps is = tempLocation ") + int(tempLocation)); scrollInstructions(); Serial.println(String("key read 'in' to be ") + int(in) + String(" after scroll")); } else { Serial.println("key 'if' !NOT! Satisfied"); } switch (in) { case '1': Serial.println("I read the number 1*"); Serial.println(String("Going to ") + int(menL)); if(menL == mainMenu) { menL = autoMenu; makeMenu(); break; } else if(menL == autoMenu) { Serial.println("Resume 1 Done"); lcd.setBacklight(TEAL); clearLCD(); lcd.setCursor(0,0); lcd.print("Press # to enter"); lcd.setCursor(0,1); lcd.println(" Manual Mode "); // keyTime = 2990; keyTime = 0; return; } else if(menL == manualMenu) { Serial.println("manualMenu"); menL = makeDistanceMenu; Serial.println("makeDistanceMenu 1"); makeMenu(); scrollInstructions(); menL = keyCheckMenu; numKeyPressed = 1; } else if(menL == manualStepMenu) { Serial.println("makeStepMenu"); keypressed = true; Serial.println("Got a Key"); clearLCD(); menL = makeDistanceMenu; makeMenu(); Serial.println(tempLocation); } else if (menL == makeDistanceMenu) { menL = makeDistanceMenu; makeMenu(); Serial.println("Read tempLocation in makeDistanceMenu"); makeDistance(in); menL = keyCheckMenu; } else if (menL == keyCheckMenu) { Serial.println(String("Read totalSteps to be ") + int(totalSteps) + String(" Read tempLocation to be ") + int(tempLocation)); keypressed = true; Serial.println(String("In menu keyCheckMenu, keypressed 'in' is ") + int(in) + String(" going to makedistance(in)")); makeDistance(in); } break; case '2': Serial.println("I read the number 2"); if(menL == mainMenu) { menL = manualMenu; makeMenu(); } else if(menL == autoMenu) { Serial.println("Re-Start 2 Done"); } else if(menL == manualMenu) { menL = manualStepMenu; makeMenu(); } else if(menL == makeDistanceMenu) { makeDistance(in); menL = makeDistanceMenu; } else if (menL == keyCheckMenu) { Serial.println(String("Read totalSteps to be ") + int(totalSteps) + String(" Read tempLocation to be ") + int(tempLocation)); keypressed = true; Serial.println(String("In menu keyCheckMenu, keypressed 'in' is ") + int(in) + String(" going to makedistance(in)")); makeDistance(in); keyTime = 0; } break; case '3': if(menL == makeDistanceMenu) { makeDistance(in); menL = makeDistanceMenu; keyTime = 0; } else if (menL == keyCheckMenu) { Serial.println(String("Read totalSteps to be ") + int(totalSteps) + String(" Read tempLocation to be ") + int(tempLocation)); keypressed = true; Serial.println(String("In menu keyCheckMenu, keypressed 'in' is ") + int(in) + String(" going to makedistance(in)")); makeDistance(in); } Serial.println("I read the number 3"); break; case '4': if(menL == makeDistanceMenu) { makeDistance(in); menL = makeDistanceMenu; } else if (menL == keyCheckMenu) { Serial.println(String("Read totalSteps to be ") + int(totalSteps) + String(" Read tempLocation to be ") + int(tempLocation)); keypressed = true; Serial.println(String("In menu keyCheckMenu, keypressed 'in' is ") + int(in) + String(" going to makedistance(in)")); makeDistance(in); } Serial.println("I read the number 4"); break; case '5': if(menL == makeDistanceMenu) { makeDistance(in); menL = makeDistanceMenu; } else if (menL == keyCheckMenu) { Serial.println(String("Read totalSteps to be ") + int(totalSteps) + String(" Read tempLocation to be ") + int(tempLocation)); keypressed = true; Serial.println(String("In menu keyCheckMenu, keypressed 'in' is ") + int(in) + String(" going to makedistance(in)")); makeDistance(in); } Serial.println("I read the number 5"); break; case '6': if(menL == makeDistanceMenu) { makeDistance(in); menL = makeDistanceMenu; } else if (menL == keyCheckMenu) { Serial.println(String("Read totalSteps to be ") + int(totalSteps) + String(" Read tempLocation to be ") + int(tempLocation)); keypressed = true; Serial.println(String("In menu keyCheckMenu, keypressed 'in' is ") + int(in) + String(" going to makedistance(in)")); makeDistance(in); } Serial.println("I read the number 6"); break; case '7': if(menL == makeDistanceMenu) { makeDistance(in); menL = makeDistanceMenu; } else if (menL == keyCheckMenu) { Serial.println(String("Read totalSteps to be ") + int(totalSteps) + String(" Read tempLocation to be ") + int(tempLocation)); keypressed = true; Serial.println(String("In menu keyCheckMenu, keypressed 'in' is ") + int(in) + String(" going to makedistance(in)")); makeDistance(in); } Serial.println("I read the number 7"); break; case '8': if(menL == makeDistanceMenu) { makeDistance(in); menL = makeDistanceMenu; } else if (menL == keyCheckMenu) { Serial.println(String("Read totalSteps to be ") + int(totalSteps) + String(" Read tempLocation to be ") + int(tempLocation)); keypressed = true; Serial.println(String("In menu keyCheckMenu, keypressed 'in' is ") + int(in) + String(" going to makedistance(in)")); makeDistance(in); } Serial.println("I read the number 8"); break; case '9': if(menL == makeDistanceMenu) { makeDistance(in); menL = makeDistanceMenu; } else if (menL == keyCheckMenu) { Serial.println(String("Read totalSteps to be ") + int(totalSteps) + String(" Read tempLocation to be ") + int(tempLocation)); keypressed = true; Serial.println(String("In menu keyCheckMenu, keypressed 'in' is ") + int(in) + String(" going to makedistance(in)")); makeDistance(in); } Serial.println("I read the number 9"); break; case '0': if(menL == makeDistanceMenu) { makeDistance(in); menL = makeDistanceMenu; } else if (menL == keyCheckMenu) { Serial.println(String("Read totalSteps to be ") + int(totalSteps) + String(" Read tempLocation to be ") + int(tempLocation)); keypressed = true; Serial.println(String("In menu keyCheckMenu, keypressed 'in' is ") + int(in) + String(" going to makedistance(in)")); makeDistance(in); } Serial.println("I read the number 0"); break; case 'A': Serial.println("I read the number A"); if( menL == manualStepMenu ) { raiseTheBoom(); } break; case 'B': Serial.println("I read the number B"); if( menL == manualStepMenu ) { lowerTheBoom(); } break; case 'C': Serial.println("I read the number C"); DIR = -1; if( menL == makeDistanceMenu ) { show(); } if( menL == manualStepMenu ) { goLeft(); } if( menL == keyCheckMenu ) { show(); } break; case 'D': Serial.println("I read the number D"); DIR = 1; if( menL == makeDistanceMenu ) { show(); } if( menL == manualStepMenu ) { goRight(); } if( menL == manualStepMenu ) { goRight(); } if( menL == keyCheckMenu ) { show(); } break; case '*': Serial.println("I read the number STOP*"); doAnAllStop(); break; case '#': Serial.println("I read the number #"); Serial.println(String("key read menL to be ") + int(menL)); if(menL == keyCheckMenu) { Serial.println("Go to Start Point"); yLocation = tempLocation - totalSteps; yLocation = abs(yLocation); Serial.println(xLocation); Serial.println(yLocation); if(xLocation >= 0 ) { DIR = -1; } else { DIR = 1; } stepsToNextStation = yLocation; Serial.println(String("Distance to move is ") + int(xLocation)); in = 0; showBack(); tempLocationSet = 0; stepsToNextStation = 0; Serial.println("Am I back? #"); menL = mainMenu; makeMenu(); } else { manualEntryPoint(); } break; default: { // delay(10000); break; } } } if (keypad.getState() == HOLD) { if ((millis() - t_hold) > 100 ) { Serial.println(holdKey); t_hold = millis(); if( in == 'C') { goLeft(); } if( in == 'D') { goRight(); } } } } void makeMenu() { switch (menL) { case mainMenu: clearLCD(); lcd.print("Automatic Manual"); lcd.print(" "); lcd.setCursor(0,1); lcd.println(" 1 or 2 "); break; case autoMenu: clearLCD(); lcd.print("Press 1 "); lcd.setCursor(0,1); lcd.print("to Re-Start "); exit; break; case manualMenu: clearLCD(); lcd.print("Number of Stps 1"); lcd.setCursor(0,1); lcd.print("Manual Mode 2"); break; case manualStepMenu: clearLCD(); raiseTheBoom(); lcd.print("Enter Direction "); lcd.setCursor(0,1); lcd.print("A=^ B=V C=< D=> "); break; case makeDistanceMenu: clearLCD(); lcd.setCursor(0,1); lcd.print("<=C or D=> to Go"); break; case keyCheckMenu: clearLCD(); lcd.setCursor(0,0); lcd.print("Enter No. "); lcd.setCursor(0,1); lcd.print("<=C or D=> to Go"); break; } } void manualEntryPoint() { stepsToNextStation = 0; inputDigitCount = 0; lcd.setCursor(0,0); lcd.print(" "); lcd.setCursor(0,0); lcd.print("Automatic Manual"); lcd.print(" "); lcd.setCursor(0,1); lcd.println(" 1 or 2 "); menL = mainMenu; inputDigitCount = 0; stepsToNextStation = 0; DIR = 0; } void doAnAllStop() { allStop(); } void tooManyDigits() { lcd.setCursor(0,0); lcd.print(" "); lcd.setCursor(0,1); lcd.print(" "); lcd.setCursor(0,1); lcd.print(" "); lcd.setCursor(0,0); lcd.print("Only 4 digits "); delay(1000); menL = makeDistanceMenu; makeMenu(); lcd.setCursor(12,0); lcd.print(stepsToNextStation); } void goLeft() { Serial.println("Manual Left"); DIR = 1; stepsToNextStation = 1; justCrawl(stepsToNextStation, DIR); // moveToNextStation(stepsToNextStation, DIR); inputDigitCount = 0; stepsToNextStation = 0; } void goRight() { Serial.println("Manual Right"); DIR = -1; stepsToNextStation = 1; justCrawl(stepsToNextStation, DIR); // moveToNextStation(stepsToNextStation, DIR); inputDigitCount = 0; stepsToNextStation = 0; } void clearLCD() { lcd.setCursor(0,0); lcd.print(" "); lcd.setCursor(0,1); lcd.print(" "); lcd.setCursor(0,0); } void makeDistance(int in) { Serial.println("Now in makeDistance(int in)"); lcd.setCursor(12,0); lcd.print(" "); keypressed = true; keyTime = 0; Serial.println(String("keyTime is set to ") + int(keyTime)); if ( in >='0' && in <='9' ) { if(inputDigitCount >= 4 ) { tooManyDigits(); } else { if(in == '0' && inputDigitCount == 0) { lcd.setCursor(0,0); lcd.print(" "); lcd.setCursor(0,0); lcd.print("Start with "); delay(1000); lcd.setCursor(0,0); lcd.print("Positive Number "); delay(1000); lcd.setCursor(0,0); lcd.print("Between 1 and 9 "); delay(1000); lcd.setCursor(0,0); lcd.print(" "); } else { inputDigitCount = inputDigitCount + 1; stepsToNextStation = stepsToNextStation * 10 + (in - '0'); Serial.println(String("Read step number to be ") + int(stepsToNextStation)); Serial.println("Read stepsToNextStation in void makeDistance"); lcd.setCursor(0,0); lcd.print(" "); lcd.setCursor(12,0); lcd.print(stepsToNextStation); } } } } void show() { // manualControl(manualStepsToNextStation, DIR); Serial.println("In Show"); lcd.setCursor(0,0); lcd.print("Go "); Serial.println(String("Read step number to be ") + int(stepsToNextStation) + String(" and DIR is ") + int(DIR)); moveToNextStation(stepsToNextStation, DIR); inputDigitCount = 0; stepsToNextStation = 0; DIR = 0; lcd.setCursor(0,0); lcd.print(" "); } void showBack() { // manualControl(manualStepsToNextStation, DIR); lcd.setCursor(0,0); lcd.print("Going Back "); moveToNextStation(stepsToNextStation, DIR); inputDigitCount = 0; stepsToNextStation = 0; DIR = 0; lcd.setCursor(0,0); lcd.print(" "); } void scrollInstructions() { while (! keypressed ) { Serial.println("while"); for (int i = 0; i < sizeof(instructions) - 16; i++) { Serial.println("Scrolling"); strncpy(scrollstring, &instructions[i], 16); lcd.setCursor(0,0); lcd.print(scrollstring); keyPadFunction(); Serial.println(String("keypresses T-F ") + int(keypressed) + String(" inside 'while' loop")); menL = keyCheckMenu; Serial.println(String("menL ") +int(menL) + String(" in 'while' loop")); delay(200); if (keypressed == true) { Serial.println("keypressed == true"); Serial.println(String("keypressed = ") +int(keypressed) + String(" after 'while' loop 'if'")); Serial.println("Read 'if' keypressed in scroll"); Serial.println("RETURN"); keypressed == true; return; } } } } void manualControl(int manualStepsToNextStation, int DIR) { Serial.println(tempLocation); stepsToNextStation + manualStepsToNextStation; moveToNextStation(stepsToNextStation, DIR); } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Just Crawl >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void justCrawl(int stepsToNextStation, int DIR) { int crawlRPM; int fullSpeed2 = 0; int currentSpeed = 1; int fakeTotalSteps = 0; int crawlDistance = 60; int crawlSpeed = 5; int opticalSensor1; int opticalSensor2; distplayDigits = 0; fakeTotalSteps = stepsToNextStation; crawlRPM = crawlRPM + 1; crawlRPM = stepsToNextStation / 2; // Serial.println(String("crawlRPM is ") + int(crawlRPM)); clearLCD(); Serial.println("Manual Crawl"); lcd.setCursor(0,0); // Upper row (0), character 1 (0) lcd.print("Crawling "); lcd.setCursor(0,1); // Upper row (0), character 1 (0) lcd.print("Y:UP "); digitalWrite(optOutPin1, HIGH); digitalWrite(optInPin1, HIGH); // turn on pullup resistors opticalSensor1 = digitalRead(optInPin1); // turn on pullup resistors // Serial.println(String("stepsToNextStation is ") + int(stepsToNextStation)); for (int i=0; i <= stepsToNextStation; i++) // Loops until it reaches the crawlDistance count. Away from sensor { opticalSensor1 = digitalRead(optInPin2); // turn on pullup resistors for All Stop sensor opticalSensor1 = digitalRead(optInPin3); // turn on pullup resistors for All Stop sensor // if (opticalSensor3 == HIGH ) // !!SET TO HIGH when sencor is installed!! // { // allStop(); // } DIR = 1; stepper.setSpeed(currentSpeed); // Set speed analogWrite(EN1_PIN, PWM); // Do the stepping PIN1 analogWrite(EN2_PIN, PWM); // Do the stepping PIN2 stepper.step(DIR); // This is a busy-wait loop until the inter-step time passes fakeTotalSteps = fakeTotalSteps - 1; location = fakeTotalSteps; lcd.setCursor(9, 1); // lcd.print(location); LCDrightJustifiedNumbers(location); // Serial.println(location); // Serial.println(String("Before 'if', currentSpeed is ") + int(currentSpeed)); // Serial.println(String("fullSpeed2 is ") + int(fullSpeed2)); if (currentSpeed <= crawlRPM && fullSpeed2 == 0) { currentSpeed = currentSpeed + 1; // Serial.println(String("1st 'if', currentSpeed is ") + int(currentSpeed)); } else { fullSpeed2 = 1; // Serial.println("fullSpeed2 = 1"); } if (fullSpeed2 == 1) { currentSpeed = currentSpeed - 1; // Serial.println(String("2nd 'if', currentSpeed is ") + int(currentSpeed)); } LCDrightJustifiedNumbers(location); return; } }