Hello guy's,i am new to arduino and microcontrollers and i have a school project.
I need to use a stteper motor , them motor needs to stop on a specific value(angle) and to turn on a led ,and the motor needs to go both ways 180 degrees total of 360 degrees full circle.I bought a A4988 driver for my motor and got it to work.
int stp = 8;
int dir = 9;
int led1=5;
int i = 0;
void setup()
{
pinMode(stp, OUTPUT);
pinMode(dir, OUTPUT);
}
void loop()
{
//--------------------------------orar---------------------
digitalWrite(dir,HIGH);
for(i=0;i<=200;i++){
digitalWrite(stp,HIGH);
delay(8);
digitalWrite(stp,LOW);
delay(8);
}
//----------------------------------trigonometric--------------------------
delay(100);
digitalWrite(dir,LOW);
for(i=201;i<=400;i++){
digitalWrite(stp,HIGH);
delay(10);
digitalWrite(stp,LOW);
delay(10);
}
delay(100);
}
here is my code so far, on the things i don't know to do is:
1.To stop the motor on a specific angle
2.read a specific value from my keyboard
Thank you PS:sorry for my bad english ,it's not my first language