Hello to all,
I'm trying to do a simple project with an Arduino Nano, a driver A4988, a stepper motor nema17 with 0,9 degrees per step, and two momentaneous press buttons.
The motor will be mounted in a variable capacitor and I want to ajust the variable capacitor in small steps to the left or right with the press buttons.
I've downloaded a library for A4988 and I could make the motor moves using an example code. The movement with example code is not very linear but works forward and backward.
All I want is to Insert two buttons. When I press button 1, the motor do 5 steps to the left each time I press the button. If I press the button 2, the motor do 5 steps to the right each time I press the button.
I started with this code:
const int EN=2; //ENABLE PIN
const int Step=3; // STEP PIN
const int dir=4; // DIRECTION PIN
/----------------------------SETUP FUNCTION--------------------------/
void setup()
{
pinMode(EN,OUTPUT); // ENABLE AS OUTPUT
pinMode(dir,OUTPUT); // DIRECTION AS OUTPUT
pinMode(Step,OUTPUT); // STEP AS OUTPUT
digitalWrite(EN,LOW); // SET ENABLE TO LOW
}
/----------------------------LOOP FUNCTION--------------------------/
void loop()
{
digitalWrite(dir,LOW); // SET DIRECTION LOW FOR FORWARD ROTATION
for(int x = 0; x < 1000; x++) // LOOP 1000 TIMES FOR 1000 RISING EDGE ON STEP PIN
{
digitalWrite(Step,HIGH); // STEP HIGH
delay(1); // WAIT
digitalWrite(Step,LOW); // STEP LOW
delay(1); // WAIT
}
delay(10); // DELAY BEFOR SWITCH DIRECTION
digitalWrite(dir,HIGH); // SET DIRECTION HIGH FOR BACKWARD ROTATION
for(int x = 0; x < 1000; x++) // LOOP 1000 TIMES FOR 1000 RISING EDGE ON STEP PIN
{
digitalWrite(Step,HIGH); // STEP HIGH
delay(1); // WAIT
digitalWrite(Step,LOW); // STEP LOW
delay(1); // WAIT
}
delay(10); // DELAY BEFOR SWITCH DIRECTION
}
Please, anyone can help me adding the function of two buttons on this code?
thanks in advance, best regards