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??