help with first project

I am having a little trouble getting my first sketch to run correctly. I am controlling a stepper motor. I have it set up to get a speed command (delay) and a length command ( step count ) from 2 different pots. I have introduced a switch, which seems to be giving me the problem. The sketch will run as I wish when I power up the board. However I want it to only run when I flip the switch on. It seems to disregard the line ( if ( oscswitch== HIGH )) in my sketch and run the loop regardless of switch position. I tested the switch with a multimeter and the switch outputs 4.9v as desired when switched on. Please help! I'm stuck.

[/
int S = 0;
int L = 0;
int D = 0;
int once = 0;
int homeswitch = 0;
int oscswitch = 0;
int limit = 0;
int countdown = 500;

void setup() {
pinMode (9,OUTPUT);//direction pin
pinMode (10, OUTPUT);// pulse pin
pinMode (11, INPUT);// Home Switch Position
pinMode (12, INPUT);// Oscillate Switch Position
pinMode (13, INPUT);// Limit Switch
digitalWrite (8, LOW);
digitalWrite (10, LOW);
digitalWrite (11, LOW);
digitalWrite (12, LOW);
digitalWrite (13, LOW);

}

void loop() {
  homeswitch=digitalRead(11);
  oscswitch=digitalRead(12);
  limit=digitalRead(13); 

  if ( oscswitch== HIGH ) {
  if(countdown==0){
  S = analogRead(A1);
  S = map(S,0,1023,400,60);
  L = analogRead(A2),
  L = map(L,0,1023,50,5000);
  countdown= 500;}
  
digitalWrite (10, HIGH);
delayMicroseconds(S);
digitalWrite(10, LOW);
delayMicroseconds(S);
D++;
countdown = countdown-1;
if( D >= L )
{
  if (digitalRead(9) == LOW){
  digitalWrite(9, HIGH);}
  else{digitalWrite(9,LOW);
}
D=0;
delay(S);
}
}
}code]

What does the meter say when the switch is off? Do you have a pull down resistor from the switch input pin to ground?

groundFungus

with switch off the reading is 0 volts. I don't have a resistor to ground.

Delta_G

I see what you are saying now. I have the countdown in so that it only reads (A1, and A2) once every 500 loops. This seems to help because the uno doesn't seem to have enough speed to read the analog inputs each loop, and maintain motor speed. Do you have any suggestions to accomplish both the analog reads on countdown (every 500 loops) and have the loop only run when it reads pin 12 HIGH.

thank you Delta_G you have been very helpful. I will make changes and get back with outcome in the morning.