Go Down

Topic: Could use some guidance with limit switches and a prox switch arduino mega (Read 1 time) previous topic - next topic

Unhinged_Reprisal

Quote
11)Repeat smiley-cool,9),& 10) 20 times

Should read
11)Repeat 8),9), & 10) 20 times.....
I don't know where the cool dude smiley came from
OOPS!
U_R

Unhinged_Reprisal

U_R

PaulS

Code: [Select]
  int i = 90000;
Yeah, right. Reading up on the range of values that can be stored in different types of variables would be a first step.

Code: [Select]
  motor2.set_microstep_select_pins(A0,A1,A2);
  motor4.set_microstep_select_pins(A0,A1,A2);

How can both motors use the same set of pins?

Code: [Select]
   for (int i = 90000; i > 0; i--);                    // Amount of maximum space i can travel
See comment above.

Code: [Select]
   if (digitalRead (switchPin1) == LOW); {     // When I trigger switch left it should read low

The ; at the end forms the body of the if statement. It's a noop (no operation/do nothing) statement. So, if the switch is pressed, do nothing. If the switch is not pressed, do nothing. What's the purpose of reading the switch state?

Code: [Select]
delay (300000);                                       //delay 5 min
Literal constants are treated as ints. 300000 is not a valid value for an int. You need UL on the end of the constant, to tell the compiler to treat the value as an unsigned long, instead.

I'm sure that there are other issues. This was as far as I read.

Unhinged_Reprisal

Paul,
  I wish I had 1/16 of the knowledge you obtain. How about this for test purposes?

(edits)
1. I am only really using A1 & A2 for motors 2 & 4
2. I changed 300000 to 3000
3. i changed rotation from 90000 900

I don't mind criticism. Please read on, I really want to know what I am doing wrong.
My father once said told me. "If you don't learn something new every day, then you are wasting your time"
Thank You,
U_R 

As well sir, could you elaborate a little to what you mean here
Quote
What's the purpose of reading the switch state?


Code: [Select]

int i = 900;
int j = 0;

void setup() {
 
  // assign the pin connections for my motors
 
  motor2.set_microstep_select_pins(A1);
   
  motor4.set_microstep_select_pins(A2);
   
// set the mag pin and the switch pins as inputs:
 
    pinMode (switchPin1, INPUT);
    pinMode (switchPin2, INPUT);
    pinMode (magPin, INPUT);
    pinMode (enablePin, OUTPUT);
   
  // create at start up command procedure to run once
  // i was thinking I could run this from void set up to run once
   
   for (int i = 900; i > 0; i--);                    // Amount of maximum space i can travel changed from 90000
   motor2.go(FULL, -i, 10);                        // Rotate motor 2 CCW from anywhere power is lost   
   if (digitalRead (switchPin1) == LOW) {  // When I trigger switch left it should read low removed semicolon
   delay (3000);                                      // Delay for 3 sec
   }                                                     // Here it will not exit void setup into void loop
  }   
 
void loop() {

//at this point switch left will read low and mag pin will be high
//so it should skip the while statement and loop back to it when the statement is true at the end of code
//also I am testing only motor 2 in this sketch for simplicity at this time

for (int x = 0; x < 20; x++);                         //repeat 20 times
while (digitalRead (magPin) == LOW){           //read prox switch low when interrupted
motor2.stall ();                                        //stop motor
delay (3000);                                       //delay 5 min
{
for (int j = 0; j < 900; j--);                     //amount of maximum space i can travel
}
for (int x = 20; x > 0; x--);                         //repeat 20 times
if (digitalRead (magPin) == HIGH){               //prox switch pin is high until triggered
motor2.go(FULL, -j, 10);                         //rotate motor CCW until prox switch is triggered
}
else {
sensorValue = digitalRead (magPin);          //read current value of prox switch should be low
delay (3000);                                    //delay for 3 sec changed from 5 min
   }
  }
}
U_R

AWOL

Code: [Select]
for (int x = 0; x < 20; x++);   
Maybe that semicolon could go to the semicolon retirement home.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up