Hello,
I will try to make my post more simple than before. I hope I am posting in the correct place. If not Please let me know...
(Run Once) from power off to power on state
1)Rotate motor 2 CCW continuously until
2)Trigger switch left (crash sensor)
3)Delay 3 sec
(Run Loop)
4)Rotate motor 4 CCW until
5)Trigger prox switch (magnetic sensor)
6)Delay 5 minutes
7)Repeat 4),5),& 6) 20 times
8)Rotate motor 2 CCW until
9)Trigger prox switch (magnetic sensor)
10)Delay 5 minutes
11)Repeat 8),9),& 10) 20 times
(Fail Safety)
If either motor 2 or motor 4 is rotating when the prox switch (mag sensor) fails,
I would want motor 2 to rotate to switch left (crash sensor1) and delay indefinitely
I would want motor 4 to rotate to switch right (crash sensor2) and delay indefinably
Thank You,
U_R
Here is some code I have been unsuccessful with.....
I am also going to leave a link to the quadstep.h library I am using from GitHub
#include <quadstep.h>
// create an instance of the class motor
quadstep motor2;
quadstep motor4;
// These constants won't change:
const int switchPin1 = 3; // pin that the limit switch is attached to for motor 2
const int switchPin2 = 12; // pin that the limit switch is attached to for motor 4
const int magPin = 8; // pin that the mag sensor is attached to for positioning
const int enablePin = 7; // pin that motor2 is attached to
// These variables will change:
int sensorLeft = 1; // left sensor value
int sensorRight = 1; // right sensor value
int sensorMag = 1; // mag sensor value
int sensorValue = 0; // the sensor value
int i = 90000;
int j = 0;
void setup() {
// assign the pin connections for my motors
motor2.set_enable_pin(7);
motor2.set_direction_pin(6);
motor2.set_step_pin(5);
motor2.set_microstep_select_pins(A0,A1,A2);
motor4.set_enable_pin(4);
motor4.set_direction_pin(27);
motor4.set_step_pin(11);
motor4.set_microstep_select_pins(A0,A1,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 = 90000; i > 0; i--); // Amount of maximum space i can travel
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
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 (300000); //delay 5 min
{
for (int j = 0; j < 90000; 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 (300000); //delay for 5 minutes
}
}
}