Hi.
Before i start, here the point from my problem:
1> About wiring connection between push button and TB6600 stepper driver
2> About code between push button and TB6600 stepper driver
Here, i want to control stepper motor rotation using push button.
What i want is when i push the button the motor will keep rotating, and then when i pull it, the motor will stop.
I want use it for calibrating of my CNC machine and manual control.
But i cant find correct wiring and the code:(, i am still trying until now.
so far right now, my code is :
int PUL = 7;
int DIR = 6;
int ENA = 5;
const int buttonPinA = 3;
const int buttonPinB = 8;
int LED = 4;
int buttonStateA = 0;
int buttonStateB = 0;
void setup()
{
pinMode (PUL, OUTPUT);
pinMode (DIR, OUTPUT);
pinMode (ENA, OUTPUT);
pinMode (LED, OUTPUT);
pinMode (buttonPinA, OUTPUT);
pinMode (buttonPinB, OUTPUT);
Serial.begin(9600);
}
void loop()
{
Serial.println("\t");
buttonStateA = digitalRead (buttonPinA);
buttonStateB = digitalRead (buttonPinB);
/// *MOTOR START*
if (buttonStateA == HIGH && buttonStateB == LOW)
{
do
{
X_AxisA();
digitalWrite(LED, LOW);
}
while (buttonStateB == HIGH);
}
else
{
digitalWrite(LED, LOW);
}
///
if (buttonStateB == HIGH)
{
X_AxisB();
digitalWrite(LED, LOW);
}
else
{
digitalWrite(LED, LOW);
}
}
void X_AxisA()
{
for (int i=0; i < 400; i++)
{
digitalWrite(DIR,LOW);
digitalWrite(ENA,HIGH);
digitalWrite(PUL,HIGH);
delayMicroseconds(100);
digitalWrite(PUL,LOW);
delayMicroseconds(100);
///---
digitalWrite(LED, HIGH);
Serial.println(i);
}
for (int i=0; i < 400; i++)
{
digitalWrite(DIR,HIGH);
digitalWrite(ENA,HIGH);
digitalWrite(PUL,HIGH);
delayMicroseconds(100);
digitalWrite(PUL,LOW);
delayMicroseconds(100);
///---
digitalWrite(LED, HIGH);
Serial.println(i);
}
}
void X_AxisB()
{
for (int i=0; i < 0; i++)
{
digitalWrite(DIR, LOW);
digitalWrite(ENA, LOW);
digitalWrite(PUL, LOW);
delayMicroseconds(100);
digitalWrite(PUL, LOW);
delayMicroseconds(100);
///---
digitalWrite(LED, LOW);
delayMicroseconds(100);
}
}
*I looking for reference on google, mostly they using POLOLU A4988 driver with push button,and on the arduino examples too. I have try using digitalRead(A0) command and if else commad.
But its not work correctly.
Can someone help me fix this?