Hi Robin,
I worked all day on my project. I'm a bit discourage. I'm sure there isn't something big which made my program not working properly.
I send you 2 different program with each different problems.
I've put some note in the right part of each program.
I'm also surprised of how many peoples read our exchange on that project.
Thank's again
Program 1 wich is in my Arduino. This one doesn't include the pause switch. The 2 limit switch are working well with a delay of 2 sec. when I hit one or the other. Always same speed wich is in the first of the 3 parts of the program
// defines pins numbers
const int stepPin = 5;
const int dirPin = 2;
const int enPin = 8;
const int LimitSwitch_LEFT_Pin = 10;
const int LimitSwitch_RIGHT_Pin = 11;
void setup() {
Serial.begin(9600);
pinMode(LimitSwitch_LEFT_Pin , INPUT);
pinMode(LimitSwitch_RIGHT_Pin , INPUT);
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(enPin,OUTPUT);
digitalWrite(enPin,LOW);
// Set Dir to Home switch
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
}
void loop() {
int leftSw = digitalRead( LimitSwitch_LEFT_Pin);
int rightSw = digitalRead( LimitSwitch_RIGHT_Pin);
{
if( (leftSw == HIGH && (digitalRead(dirPin) == HIGH)) ||
(rightSw == HIGH && (digitalRead(dirPin) == LOW)) ){
digitalWrite(stepPin,HIGH);
delayMicroseconds(500); // ALWAYS THIS SPEED IS SELECTED
digitalWrite(stepPin,LOW); // SWITCH ARE WORKING WELL
delayMicroseconds(500);
}
if( leftSw == LOW && (digitalRead(dirPin) == HIGH) ){
digitalWrite(dirPin,LOW);
delay(2000);
digitalWrite(stepPin,HIGH);
delayMicroseconds(2000); // THIS SPEED NOT WORKING
digitalWrite(stepPin,LOW);
delayMicroseconds(2000);
}
if( rightSw == LOW && (digitalRead(dirPin) == LOW ) ){
digitalWrite(dirPin,HIGH);
delay(2000);
digitalWrite(stepPin,HIGH);
delayMicroseconds(4000); // THIS SPEED NOT WORKING
digitalWrite(stepPin,LOW);
delayMicroseconds(4000);
}}}
Now the second program with all your modifications. This one include the stop switch. Neither the 3 switch are working and the speed is always in the same direction and the speed is the one in the last part of the program.
// defines pins numbers
const int stepPin = 5;
const int dirPin = 2;
const int enPin = 8;
const int LimitSwitch_LEFT_Pin = 10;
const int LimitSwitch_RIGHT_Pin = 11;
const int StopSw_Pin = 12;
char direction = 'F'; // <----------------------NEW
unsigned long intervalBetweenSteps;
void setup() {
Serial.begin(9600);
pinMode(LimitSwitch_LEFT_Pin , INPUT);
pinMode(LimitSwitch_RIGHT_Pin , INPUT);
pinMode(StopSw_Pin , INPUT);
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(enPin,OUTPUT);
digitalWrite(enPin,LOW);
// Set Dir to Home switch
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
}
void loop() {
byte leftSw = digitalRead( LimitSwitch_LEFT_Pin);
byte rightSw = digitalRead( LimitSwitch_RIGHT_Pin);
byte stopSw = digitalRead(stopSw);
if (leftSw == LOW and direction == 'L') { // assumes LOW when pressed
direction = 'R'; // THIS SPEED NOT WORKING
delay(2000); // SWITCH DOESN'T WORK
intervalBetweenSteps = 3000;
}
if (rightSw == LOW and direction == 'R') {
direction = 'L'; // THIS SPEED NOT WORKING
delay(2000); // SWITCH DOESN'T WORK
intervalBetweenSteps = 5000;
}
if (stopSw == HIGH) { // assumes HIGH when not pressed SWITCH DOESN'T WORKING
motorStep();
}
}
void motorStep(){
if (direction == 'R') {
digitalWrite(dirPin, HIGH);
}
else {
digitalWrite(dirPin, LOW);
}
digitalWrite(stepPin,HIGH);
delayMicroseconds(5000); // short step pulse ALWAYS THIS SPEED IS SELECTED
digitalWrite(stepPin,LOW); // SWITCH DOESN'T WORK
delayMicroseconds(5000);
}