The first arduino sketch:
int Distance = 0; // Record the number of steps we've taken
void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}
void loop() {
digitalWrite(9, HIGH);
delayMicroseconds(100);
digitalWrite(9, LOW);
delayMicroseconds(100);
Distance = Distance + 1; // record this step
// Check to see if we are at the end of our move
if (Distance == 3600)
{
// We are! Reverse direction (invert DIR signal)
if (digitalRead(8) == LOW)
{
digitalWrite(8, HIGH);
}
else
{
digitalWrite(8, LOW);
}
// Reset our distance back to zero since we're
// starting a new move
Distance = 0;
// Now pause for half a second
delay(500);
}
}
The second arduino sketch:
#define DISTANCE 3200
int StepCounter = 0;
int Stepping = false;
void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
pinMode(3,INPUT);
}
void loop() {
if (digitalRead(3) == LOW && Stepping == false)
{
Stepping = true;
}
if (Stepping == true)
{
digitalWrite(9, HIGH);
delay(1);
digitalWrite(9, LOW);
delay(1);
StepCounter = StepCounter + 1;
if (StepCounter == DISTANCE)
{
StepCounter = 0;
Stepping = false;
}
}
}
I have tested both programs individually and it worked.
I was wondering if if i can combine both programs together.
Can someone please help?
Thank you!! Appreciate much!!