help micro elevator code

hi all i want write a code for a micro elevator moved with a stepper, but i have many doubts
for example a believe that my code using the switch sentence its wrong, but im not so sure, for example i want to control the elevator using the 4 buttoms attached to the digital pins 2-5, but using a counter called Floor to let me know in which floor the elevatr its, and depending on that if any buttom its trigger then the stepper will move on the direcction to reach the floor in which the elevator was called, and also decrementing or adding floor to the counter Floor[/b
here its my code untill now:
```
*/
Stepper elevator Control -

This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 10-11 of the Arduino.

The push buttoms selects the floor and the stepper spin till
the hall sensor its trigger enough ties o reach the floor the push buttoms selects.

Created 18 Nov. 2012
by Cesar flores

*/

#include <Stepper.h>
const int hall = 12;     // the number of the hall effect sensor pin
const int stepsPerRevolution = 200;  
const int  Floor1 = 2;
const int  Floor2 = 3;
const int  Floor3 = 4;
const int  Floor4 = 5;

// initialize the stepper library on pins 10 11:
Stepper myStepper(stepsPerRevolution, 10,11);            
int hallcount=0;
int Floor = 1;         // the floor the elvator its

void setup() {
 // initialize the hall effect sensor pin as an input:
myStepper.setSpeed(30);
pinMode(hall, INPUT);
pinMode(Floor1, INPUT);
pinMode(Floor2, INPUT);
pinMode(Floor3, INPUT);
pinMode(Floor4, INPUT);
}

void loop() {
 if (hall==HIGH);{
 hallcount++;}
 switch (Floor)
 {
 case 1:
 {if (Floor==1 && Floor1==HIGH);
 {
 
   myStepper.step(0);
 
  Floor=Floor;
 }
 if(Floor==1 && Floor2==HIGH);
 {
 myStepper.step(400);//here its my problem i want to move the stepper till its reach the hall sensor
 Floor++;  
 
 }
 if(Floor==1 && Floor3==HIGH);
 {
  myStepper.step(400);
 Floor=Floor+2;
 
 }
 if(Floor==1 && Floor4==HIGH);
 {
   myStepper.step(400);
  Floor=Floor+3;
 
}
 }
break;

case 2:
 {if (Floor==2 && Floor1==HIGH);
 {
  myStepper.step(400);
   
   Floor--;
 }
 if(Floor==2 && Floor2==HIGH);
 {
 myStepper.step(400);
 Floor=Floor;
 }
 if(Floor==2 && Floor3==HIGH);
 {
  myStepper.step(400);
 Floor++;
 }
 if(Floor==2 && Floor4==HIGH);
 {
   myStepper.step(400);
  Floor=Floor+2;
 }
 }
 break;
 
 
 case 3:
 {if (Floor==3 && Floor1==HIGH);
 {
  myStepper.step(400);
 
  Floor=Floor-2;
 }
 if(Floor==3 && Floor2==HIGH);
 {
 myStepper.step(400);
 Floor--;  
 }
 if(Floor==3 && Floor3==HIGH);
 {
  myStepper.step(400);
 Floor=Floor;
 }
 if(Floor==3 && Floor4==HIGH);
 {
   myStepper.step(400);
  Floor++;
 }
 }
 break;
 
 case 4:
 {if (Floor==4 && Floor1==HIGH);
 {
 myStepper.step(400);
 
  Floor=Floor-3;
 }
 if(Floor==4 && Floor2==HIGH);
 {
 myStepper.step(400);
 Floor=Floor-2;
 }
 if(Floor==4 && Floor3==HIGH);
 {
  myStepper.step(400);
   
   
 Floor=Floor-1;
 }
 if(Floor==1 && Floor4==HIGH);
 {
 myStepper.step(400);  
  Floor=Floor;
 }
 }
 break;

}  
}**
** **as you can see there its also a hall effect sensor, the sensor its on the elevator and on the floor are magnets, but im not so sure how to increment or decrement the hallcounter, so the stepper spin on the direction it needs, but when the counter reches the floor its was called the sterpper stops..** **for example if i move the elevator from the floor 1 till the 4, the hallcounter need to reach 4 for the stepper to stops, in the code says** **
if(Floor==1 && Floor4==HIGH);
 {
 myStepper.step(400);

** **but i want to change the 400 for something that only moves the stepper on the CCW direction and when the hall counter reach for the stepper stops** **
if(Floor==1 && Floor4==HIGH);
 {
 myStepper.step(foward);
if hallcounter==4
if(Floor==1 && Floor4==HIGH);
 {
 myStepper.step(stops);

```
this can be done??

if (hall==HIGH);{

I stopped reading there.

its that a code mistake???

Yes, and there are lots of them. (I fibbed about stopping reading)

im rally noob on arduino programming, and i suck on programmig in c as well, so if you can point the mistakes, you can help me a lot....

the idea on that part its that always when the hall sensor gets high increment the hall counter, so i can stop the stepper right on the for its needed

Here's another classic mistake (two on one line no less!):

  if (hall==HIGH)

You're testing the pin number against HIGH. Hall is 12, it'll never be HIGH. You need to be using digitalRead. It might help to change hall to hallpin to remind you.

Another potential problem is that even when you read the Hall effect device, the HIGH may persist for several "loop()" cycles.
You're better of detecting when the state changes (high to low or low to high), not when it is in a single state.

hall=digitalRead;
  if digitalRead==HIGH;
hallcount++;

or i am still in the same?? maybe im dumb...

also in the cases those Floor==HIGH are wrong... or not

{if (Floor==1 && Floor1==HIGH);

the best would be to use interrupts on the hall pin

attachInterrupt(0, count, RISING);
void count{
hallcount++

What is the value of Floor1?
Is it ever going to be equal to HIGH?

Have you ever seen a semicolon at the end of an "if" in any of the example code?

Floor1,2,3,4 are always LOW, its activaded with a push buttom so when it changes from LOW to HIGH the if code can be executed

and if i dont use a semicolon afer the "if" the IDE ask for it.... that why i used then

Floor1,2,3,4 are always LOW

No, they're not.

const int  Floor1 = 2;
const int  Floor2 = 3;
const int  Floor3 = 4;
const int  Floor4 = 5;

that what it makes me doubt when i write it,

i didnt know if arduino recognize the state of the push buttom or the pin the buttom its attached to..

i didnt know if arduino recognize the state of the push buttom or the pin the buttom its attached to.

you don't know the state of a pin until you read it.

i see, but its better to read the buttoms in the case sentence or before the switch???

reading the state of the pins would be like this right

  val1=digitalRead(Floor1);
  val2=digitalRead(Floor2);
  val3=digitalRead(Floor3);
  val4=digitalRead(Floor4);
  
  


  switch (Floor)
  {
  case 1:
  {if (Floor==1 && val1==HIGH)
  {
  
    myStepper.step(0);
   
   Floor=Floor; 
  }
  if(Floor==1 && val2==HIGH)
  {
  myStepper.step(400);//here its my problem i want to move the stepper till its reach the hall sensor
  Floor++;  
  
  }
  if(Floor==1 && val3==HIGH);
  {
   myStepper.step(400); 
  Floor=Floor+2;
  
  }
  if(Floor==1 && val4==HIGH);
  {
    myStepper.step(400);
   Floor=Floor+3; 
  
}
  }
break;

Have you tried to compile and run the examples included with the Arduino IDE ?

yes and also my code compile, but its 100% my code doesnt work.... it need tobe changed

Well, you need to fix the problems already pointed out.
Then you need to run it, and figure out what it is that it does that you didn't expect it to, and what it didn't do that you did expect it to.
Debug prints are useful for this.

yes i now, but i can test it till tomorrow when the stepper driver its ready, but i need to know now how can i make the stepper to run without tellihn how many steps i need to move it

reading the state of the pins would be like this right

Yes, but...

Later in your code, what does val1 mean? Could you infer what floorSwitchState1 meant? Which is easier to understand?

Now, it makes no difference to the compiler. Everything is translated to a memory address as far as the compiler is concerned. But, long before the compiler has spent a few seconds with your code, you (and we) will have spent hours trying to understand what it is doing. Why not make it easy on yourself and use meaningful names?

Could this be a case of the elevator not going all the way to the top?

Bob