Help debugging code - switch doesn't work

Hello and thank you for your time,

I'm working on a project for school, I'm really not the best at programming. I've tried this code a zillion different ways, so if you would like another iteration, I could provide. I think this is the most elegant solution I've come up with, but I feel like I'm up against a wall, and I'm really just out of ideas as to what to try.

I need my program to engage a dc motor when one of two switches are pressed. It needs to run at a certain speed for a certain amount of time in both cases. Flipping switch one will launch for the distance competition and flipping switch two will launch the accuracy competition. A certain amount of time after either switch is flipped, a servo needs to engage.

I'm attaching my code.. I don't know what exactly to call it, a conditional sort of code. I've also got it with if and while statements if you'd like to see. In either case, the switch isn't working and this project is due on thursday! I would appreciate any insight, I hope you can help me.

#include <AccelStepper.h>

#include <Stepper.h>


#include <Servo.h>
#include <Adafruit_MotorShield.h>
#include <Wire.h>



Adafruit_MotorShield AFMS = Adafruit_MotorShield();



Adafruit_DCMotor *DC1 = AFMS.getMotor(1);
Adafruit_DCMotor *DC2 = AFMS.getMotor(2);
Adafruit_DCMotor *DC3 = AFMS.getMotor(3);
Adafruit_DCMotor *DC4 = AFMS.getMotor(4);

Servo Servo1;



void setup() {
  digitalWrite(A0, HIGH); //Turns on the pullup resistor for A0
  AFMS.begin(); //Initializes the motorshield board

  int motorPin1 = 1;
  int motorPin2 = 2;
  int motorPin3 = 3;
  int motorPin4 = 4;




  pinMode(A0, INPUT); //Sets the Analog Pin 0 as an input
  digitalWrite(A0, HIGH);
  pinMode(A1, INPUT);
  digitalWrite(A1, HIGH);
  pinMode(A1, INPUT);
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  Servo1.attach(9);






}



void loop()  {
  int distancepin = 0;  //Just integer quantities, i like to have too many of them
  int accuracypin = 0;
  int MAXampDrawTime = 1000;
  int MAXampDrawSpeed = 20;
  int NORMampDrawTime = 1500;
  int NORMampDrawSpeed = 10;
  int DrawTime = MAXampDrawTime + NORMampDrawTime;
  int ServoTime = 450;
  int previousMillis = 0;
  int inPin0 = LOW;
  int inPin1 = LOW;
  inPin0 = digitalRead(A0);
  inPin1 = digitalRead(A1);
  unsigned long time_zero = millis();
  unsigned long current_time = millis();

  if (inPin0 == HIGH) {
    time_zero = millis();
    current_time = millis();
    while (millis() - time_zero < MAXampDrawTime); {
      dcMoveConst(MAXampDrawSpeed, 1);
      dcMoveConst(MAXampDrawSpeed, 2);
      dcMoveConst(MAXampDrawSpeed, 3);
      dcMoveConst(MAXampDrawSpeed, 4);
    }
    while (millis() - time_zero < NORMampDrawTime); {

      dcMoveConst(NORMampDrawSpeed, 1);
      dcMoveConst(NORMampDrawSpeed, 2);
      dcMoveConst(NORMampDrawSpeed, 3);
      dcMoveConst(NORMampDrawSpeed, 4);
    }
    if (millis() - time_zero > DrawTime) {
      dcMoveConst(0, 1);
      dcMoveConst(0, 2);
      dcMoveConst(0, 3);
      dcMoveConst(0, 4);
    }
  }
  if (millis() - time_zero >= ServoTime); {


    Servo1.write(0);
    delay(400);
    Servo1.write(90);

  }

  if (inPin1 == HIGH) {
    time_zero = millis();
    current_time = millis();
    MAXampDrawTime = 1000;
    MAXampDrawSpeed = 20;
    NORMampDrawTime = 1500;
    NORMampDrawSpeed = 10;
    DrawTime = MAXampDrawTime + NORMampDrawTime;
    while (millis() - time_zero < MAXampDrawTime); {
      dcMoveConst(MAXampDrawSpeed, 1);
      dcMoveConst(MAXampDrawSpeed, 2);
      dcMoveConst(MAXampDrawSpeed, 3);
      dcMoveConst(MAXampDrawSpeed, 4);
    }
    while (millis() - time_zero < NORMampDrawTime); {

      dcMoveConst(NORMampDrawSpeed, 1);
      dcMoveConst(NORMampDrawSpeed, 2);
      dcMoveConst(NORMampDrawSpeed, 3);
      dcMoveConst(NORMampDrawSpeed, 4);
    }
    if (millis() - time_zero > DrawTime) {
      dcMoveConst(0, 1);
      dcMoveConst(0, 2);
      dcMoveConst(0, 3);
      dcMoveConst(0, 4);


    }
  }
  if (millis() - time_zero >= ServoTime); {


    Servo1.write(0);
    delay(400);
    Servo1.write(90);
  }


}

Oh, you know what? I accidentally grabbed an old version of my code. I think my new way might be the way to go. Oops. But that is very good to know about the semicolons. I'll check for that mistake! edit: i removed the colons from this code as well. Thank you for that heads up.

#include <Servo.h>
#include <Adafruit_MotorShield.h>
#include <Wire.h>



Adafruit_MotorShield AFMS = Adafruit_MotorShield();



Adafruit_DCMotor *DC1 = AFMS.getMotor(1);
Adafruit_DCMotor *DC2 = AFMS.getMotor(2);
Adafruit_DCMotor *DC3 = AFMS.getMotor(3);
Adafruit_DCMotor *DC4 = AFMS.getMotor(4);

Servo Servo1;



void setup() {
  digitalWrite(A0, HIGH); //Turns on the pullup resistor for A0
  AFMS.begin(); //Initializes the motorshield board

  int motorPin1 = 1;
  int motorPin2 = 2;
  int motorPin3 = 3;
  int motorPin4 = 4;




  pinMode(A0, INPUT); //Sets the Analog Pin 0 as an input
  digitalWrite(A0, LOW);
  pinMode(A1, INPUT);
  digitalWrite(A1, LOW);
  pinMode(A1, INPUT);
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  Servo1.attach(9);
#define s_idle 1
#define s_maxthrow 2
#define s_accthrow 3
#define s_waitservo 4
#define s_servogo 5
#define s_turnoff 6
#define s_decide 7

  int inPin0 = LOW;
  int inPin1 = LOW;
  inPin0 = digitalRead(A0);
  inPin1 = digitalRead(A1);
}



void loop()  {
  static int state = s_idle; // initial state is 1, the idle state
  static unsigned long ts; // to store the current time in for delays

  int MAXampDrawTime;
  int MAXampDrawSpeed;
  int NORMampDrawTime;
  int NORMampDrawSpeed;
  int servoTime = 450;
  int inPin0 = LOW;
  int inPin1 = LOW;
  int DrawTime;
  inPin0 = digitalRead(A0);
  inPin1 = digitalRead(A1);

  switch (state) {
    case s_idle:
      dcRelease(1);
      dcRelease(2);
      dcRelease(3);
      dcRelease(4);
      break;


    case s_decide:
      if (digitalRead(A0) != inPin0) {
        state = s_maxthrow;
      }
      if (digitalRead(A1) != inPin1) {
        state = s_accthrow;
      }
    case s_maxthrow:

      MAXampDrawTime = 500;
      MAXampDrawSpeed = 30;
      NORMampDrawTime = 250;
      NORMampDrawSpeed = 20;
      DrawTime = MAXampDrawTime + NORMampDrawTime;

      ts = millis();

      dcMoveConst(MAXampDrawSpeed, 1);
      dcMoveConst(MAXampDrawSpeed, 2);
      dcMoveConst(MAXampDrawSpeed, 3);
      dcMoveConst(MAXampDrawSpeed, 4);
      delay(MAXampDrawTime);
      dcMoveConst(NORMampDrawSpeed, 1);
      dcMoveConst(NORMampDrawSpeed, 2);
      dcMoveConst(NORMampDrawSpeed, 3);
      dcMoveConst(NORMampDrawSpeed, 4);
      delay(NORMampDrawTime);
      state = s_turnoff;



    case s_turnoff:
      dcRelease(1);
      dcRelease(2);
      dcRelease(3);
      dcRelease(4);
      state = s_idle;
      break;

    case s_accthrow:


      MAXampDrawTime = 1000;
      MAXampDrawSpeed = 30;
      NORMampDrawTime = 750;
      NORMampDrawSpeed = 20;
      DrawTime = MAXampDrawTime + NORMampDrawTime;

      ts = millis();

      dcMoveConst(MAXampDrawSpeed, 1);
      dcMoveConst(MAXampDrawSpeed, 2);
      dcMoveConst(MAXampDrawSpeed, 3);
      dcMoveConst(MAXampDrawSpeed, 4);
      delay(MAXampDrawTime);
      dcMoveConst(NORMampDrawSpeed, 1);
      dcMoveConst(NORMampDrawSpeed, 2);
      dcMoveConst(NORMampDrawSpeed, 3);
      dcMoveConst(NORMampDrawSpeed, 4);
      delay(NORMampDrawTime);
      state = s_turnoff;



    case s_servogo:
      if (millis() - ts > servoTime) {
        Servo1.write(0);
        delay(400);
        Servo1.write(90);
      }
      default:
      state = s_idle;
      break;
  }
}

I really appreciate the feedback, i fixed those errors and the motor still won't engage.

, i fixed those errors

But you didn't post the fixed code.

Sorry!

#include <AccelStepper.h>

#include <Stepper.h>


#include <Servo.h>
#include <Adafruit_MotorShield.h>
#include <Wire.h>



Adafruit_MotorShield AFMS = Adafruit_MotorShield();



Adafruit_DCMotor *DC1 = AFMS.getMotor(1);
Adafruit_DCMotor *DC2 = AFMS.getMotor(2);
Adafruit_DCMotor *DC3 = AFMS.getMotor(3);
Adafruit_DCMotor *DC4 = AFMS.getMotor(4);

Servo Servo1;



void setup() {
  digitalWrite(A0, HIGH); //Turns on the pullup resistor for A0
  AFMS.begin(); //Initializes the motorshield board

  int motorPin1 = 1;
  int motorPin2 = 2;
  int motorPin3 = 3;
  int motorPin4 = 4;




  pinMode(A0, INPUT); //Sets the Analog Pin 0 as an input
  digitalWrite(A0, LOW);
  pinMode(A1, INPUT);
  digitalWrite(A1, LOW);
  pinMode(A1, INPUT);
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  Servo1.attach(9);
#define s_idle 1
#define s_maxthrow 2
#define s_accthrow 3
#define s_waitservo 4
#define s_servogo 5
#define s_turnoff 6
#define s_decide 7


}



void loop()  {
  static int state = s_idle; // initial state is 1, the idle state
  static unsigned long ts; // to store the current time in for delays

  int MAXampDrawTime;
  int MAXampDrawSpeed;
  int NORMampDrawTime;
  int NORMampDrawSpeed;
  int servoTime = 450;
  int inPin0 = LOW;
  int inPin1 = LOW;
  int DrawTime;
  inPin0 = digitalRead(A0);
  inPin1 = digitalRead(A1);

  switch (state) {
    case s_idle:
      dcRelease(1);
      dcRelease(2);
      dcRelease(3);
      dcRelease(4);
      break;


    case s_decide:
      if (digitalRead(A0) != inPin0) {
        state = s_maxthrow;
      }
      if (digitalRead(A1) != inPin1) {
        state = s_accthrow;
      }
      break;
    case s_maxthrow:

      MAXampDrawTime = 500;
      MAXampDrawSpeed = 30;
      NORMampDrawTime = 250;
      NORMampDrawSpeed = 20;
      DrawTime = MAXampDrawTime + NORMampDrawTime;

      ts = millis();

      dcMoveConst(MAXampDrawSpeed, 1);
      dcMoveConst(MAXampDrawSpeed, 2);
      dcMoveConst(MAXampDrawSpeed, 3);
      dcMoveConst(MAXampDrawSpeed, 4);
      delay(MAXampDrawTime);
      dcMoveConst(NORMampDrawSpeed, 1);
      dcMoveConst(NORMampDrawSpeed, 2);
      dcMoveConst(NORMampDrawSpeed, 3);
      dcMoveConst(NORMampDrawSpeed, 4);
      delay(NORMampDrawTime);
      state = s_turnoff;
      break;



    case s_turnoff:
      dcRelease(1);
      dcRelease(2);
      dcRelease(3);
      dcRelease(4);
      state = s_idle;
      break;

    case s_accthrow:


      MAXampDrawTime = 1000;
      MAXampDrawSpeed = 30;
      NORMampDrawTime = 750;
      NORMampDrawSpeed = 20;
      DrawTime = MAXampDrawTime + NORMampDrawTime;

      ts = millis();

      dcMoveConst(MAXampDrawSpeed, 1);
      dcMoveConst(MAXampDrawSpeed, 2);
      dcMoveConst(MAXampDrawSpeed, 3);
      dcMoveConst(MAXampDrawSpeed, 4);
      delay(MAXampDrawTime);
      dcMoveConst(NORMampDrawSpeed, 1);
      dcMoveConst(NORMampDrawSpeed, 2);
      dcMoveConst(NORMampDrawSpeed, 3);
      dcMoveConst(NORMampDrawSpeed, 4);
      delay(NORMampDrawTime);
      state = s_turnoff;
      break;



    case s_servogo:
      if (millis() - ts > servoTime) {
        Servo1.write(0);
        delay(400);
        Servo1.write(90);
      }
      default:
      state = s_idle;
      break;
  }
}

That's a lot of code for hardware that doesn't work. Ditch 90 % of that code until you KNOW that each instance of the motor class works to make one motor move both directions.

Delta_G:
What is the problem with this version? What does it do or not do? How does that compare with what you want?

It doesn't engage the motor. I want it to turn the motor when the switch flips.

I think I will break it up into easier to understand chunks as was suggested by PaulS. I'll keep you posted, the feedback here definitely helped, and I'll probably have questions still. Thanks!

And another post by a person whose basic problem is that they haven't read a definition of C/C++ syntax and are trying to program by example.

A statement list is a series of statments enclosed in braces.

A statement can be one of the flow-control statements (if, if-else, do-wile, while, for)
A statement can be an expression followed by a semicolon.
A statement can be a semicolon all by itself - the "do nothing" statment.
A statement can be a statement list

Function calls and assignments are treated as expressions that happen to have side-effects.

An if statement looks like this: if(expression) statement
A while statement looks like this: while(expression) statement
A for statement looks like this: for(expression;expression;expression) statement

This means that this:

if (millis() - time_zero >= ServoTime);
{
   do_some_stuff();
}

Is treated as

if(condition) 
  do-nothing
statement-list
  expression followed by semicolon

What you want is

if(condition) 
  statement-list
    expression followed by semicolon

So get rid of the empty do-nothing statement after the if()