Hallo,
I tried to find answer for this before, but I saw only another question wich was not fit to mine.
I am work on one small project with arduino and need to use two modes for stepp motor moving.
this is the code I have got...
int Pin4 = 6;
int Pin5 = 7;
int Pin6 = 8;
int Pin7 = 9;
int _step = 0;
boolean dir = true;
const int buttonPin = 5 ;
int buttonState = 0;
int i=0;
void setup()
{
pinMode(buttonPin,INPUT);
pinMode(Pin4, OUTPUT);
pinMode(Pin5, OUTPUT);
pinMode(Pin6, OUTPUT);
pinMode(Pin7, OUTPUT);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH){
for(i=0;i<48;i++){
{//vykonanie ak je zopnuty spinac I
switch(_step){
case 0:
digitalWrite(Pin4, LOW);
digitalWrite(Pin5, LOW);
digitalWrite(Pin6, LOW);
digitalWrite(Pin7, HIGH);
break;
case 1:
digitalWrite(Pin4, LOW);
digitalWrite(Pin5, LOW);
digitalWrite(Pin6, HIGH);
digitalWrite(Pin7, HIGH);
break;
case 2:
digitalWrite(Pin4, LOW);
digitalWrite(Pin5, LOW);
digitalWrite(Pin6, HIGH);
digitalWrite(Pin7, LOW);
break;
case 3:
digitalWrite(Pin4, LOW);
digitalWrite(Pin5, HIGH);
digitalWrite(Pin6, HIGH);
digitalWrite(Pin7, LOW);
break;
case 4:
digitalWrite(Pin4, LOW);
digitalWrite(Pin5, HIGH);
digitalWrite(Pin6, LOW);
digitalWrite(Pin7, LOW);
break;
case 5:
digitalWrite(Pin4, HIGH);
digitalWrite(Pin5, HIGH);
digitalWrite(Pin6, LOW);
digitalWrite(Pin7, LOW);
break;
case 6:
digitalWrite(Pin4, HIGH);
digitalWrite(Pin5, LOW);
digitalWrite(Pin6, LOW);
digitalWrite(Pin7, LOW);
break;
case 7:
digitalWrite(Pin4, HIGH);
digitalWrite(Pin5, LOW);
digitalWrite(Pin6, LOW);
digitalWrite(Pin7, HIGH);
break;
default:
digitalWrite(Pin4, LOW);
digitalWrite(Pin5, LOW);
digitalWrite(Pin6, LOW);
digitalWrite(Pin7, LOW);
break;
} ///
}
if(dir){
_step++;
}else{
_step--;
}
if(_step>7){
_step=0;
}
if(_step<0){
_step=7;
}
delay(1);
}
};
[color=red]delay(5000);[/color]
}
My problem in this case is: I want to rewrite this code in order to step motor rotate 360 degrees and then stop. . Motor has 48 steps. I tried to use for cycle for that and delay 5 sec.
If button is pressed it should start, than make one full turn /48 steps/ and wait for 5 sec.
Why it isnt working ? what is wrong ? ... I know it is loop , but it should do all cases 48 times - and wait.
There are "if" part of code for changing directions too, I want to use it for changig direction with press button. / I tried it in another code it works well - that is not my problem , my problem is to make it works for one turn and wait for some time /
Thank you for advices ...