DC motor control with switches

So I have 3 switches

(Switch 1: inspectionready, Switch 2:stopmotor, Switch 3:inspection stop)

so when switch 1 is pushed
motor will rotate clockwise
if switch 2 is pushed stop motor
if switch 1 is pushed again
motor will rotate clockwise
then motor stop

finally is switch 3 is pushed program will end.

i am having trouble with making switch one to make the motor turn clock wise
then stop when switch 2 is pressed
then when switch 1 is pressed again motor will turn counter clockwise
then stop when switch 2 is pressed
*********

please help i am a newb...i have looked a bunch of examples....

const int inspectready = 2;
const int stopmotor = 3;
const int inspectstop = 4;
const int camera = 9;
const int light = 10;
const int motorcw = 11;
const int motorccw = 12;

// variables will change:
int startbutton = 0; // variable for reading the pushbutton status
int inspectiondone = 0;
int motorstop = 0;

void setup() {

pinMode(inspectready, INPUT);
pinMode(stopmotor, INPUT);
pinMode(inspectstop, INPUT);
pinMode(camera, OUTPUT);
pinMode(light, OUTPUT);
pinMode(motorcw, OUTPUT);
pinMode(motorccw, OUTPUT);
}

void loop(){
startbutton = digitalRead(inspectready);
motorstop = digitalRead(stopmotor);
inspectiondone = digitalRead(inspectstop);

while(inspectiondone == LOW){
while (startbutton = HIGH){
if(startbutton = HIGH){
digitalWrite(camera, HIGH);
digitalWrite(light, HIGH);
digitalWrite(motorcw, HIGH);
}
while (startbutton == HIGH) {
if (startbutton == HIGH){
digitalWrite(camera, HIGH);
digitalWrite(light, HIGH);
digitalWrite(motorccw, HIGH);
}
else if (motorstop == HIGH) {
digitalWrite(camera, LOW);
digitalWrite(light, LOW);
digitalWrite(motorcw, LOW);
digitalWrite(motorccw, LOW);
}}
}}
}

I see one problem... you assume that LOW is 0 and probably that HIGH is 1. Although that may be right, you should be consistent in your code to prevent problems that are hard to track down.

so this:

int inspectiondone = 0;

and this:

while(inspectiondone == LOW){

May not give you the expected results. I know this is not the problem, it's just an advice.

Then the other thing I see is infinite loops... loads of them...

void loop(){  //you read the pins once... 
  startbutton = digitalRead(inspectready);
  motorstop = digitalRead(stopmotor);
  inspectiondone = digitalRead(inspectstop);

  
while(inspectiondone == LOW){ //then if inspectiondone goes low, you have one infinite loop here...
while (startbutton = HIGH){      //then you assign startbutton and therefore, you'll have another infinite loop here--- 
   if(startbutton = HIGH){
    digitalWrite(camera, HIGH);
    digitalWrite(light, HIGH);  
    digitalWrite(motorcw, HIGH);  
  }
while (startbutton == HIGH) {//this is another infinite loop and a redundant one... 
  if (startbutton == HIGH){
    digitalWrite(camera, HIGH);
    digitalWrite(light, HIGH);  
    digitalWrite(motorccw, HIGH);
  }
  else if (motorstop == HIGH) {
    digitalWrite(camera, LOW);
    digitalWrite(light, LOW);  
    digitalWrite(motorcw, LOW);
    digitalWrite(motorccw, LOW);
  }}
}}
}

Can you try this?

void loop(){

while((inspectiondone=digitalRead(inspectstop)) == LOW){
  if ((startbutton=digitalRead(inspectready)) == HIGH){
    digitalWrite(camera, HIGH);
    digitalWrite(light, HIGH);  
    digitalWrite(motorccw, HIGH);
  }
  else if ((motorstop= digitalRead(stopmotor)) == HIGH) {
    digitalWrite(camera, LOW);
    digitalWrite(light, LOW);  
    digitalWrite(motorcw, LOW);
    digitalWrite(motorccw, LOW);
  }}
}}
}

I did not understand your conditions to start and stop the motor... but I think you are complicating things way too much for what you described. Either way, you don't have infinite cycles in the code now.

As bubulindo observes, your while loops are causing you issues, as written, your program will only read the buttons once. Assuming you weren't pressing the InspectionStop button when the program started, it will spin in the first loop, doing nothing, forever.

A more effective approach would be to build a state machine: you only need a few states - start, cw, stop, ccw, end inspection. Read the buttons at the start of loop & then use a switch statement based on current state to see if the buttons indicate a need for state change. If they do, set your outputs appropriately and change state. Then loop will be called repeatedly, rather than once as you have it. There are plenty of examples of this posted in the forums - I gave one in this thread: What have I done right/wrong? - #9 by wildbill - Programming Questions - Arduino Forum