please help me to correct the code if i change the delay time code not working
thank you
/////M Kamran Robot Crane Hidden experiments Forbidden projects public don't care Event base Arduino program Crane assembly - YouTube
/// ///this is code for automatic crane pick and place proto type crane logic by switches and all operation with direct voltage through relay operation and AT mega try it and tell me about any findings
//with timers its working fine but when i change delay some time problem please help this model works with magnatic lifting which is energized with relay switchesthanks mail me robot78p@gmail.com
///int mode = 2; // select mode AUTO/MANUAL if HIGH=AUTO else LOW=MANUAL
///int start = 3; // select START/STOP auto mode
///int tool = 8; // tool Sw
////int modeState = 1; //modelState
////int startState = 1; //start1State
////int toolState = 1;
int sw1 = 6;
int sw2 = 7;
int sw3 = 8;
int sw4 = 9;
int relay1 = 23;
int relay2 = 25;
int relay3 = 27;
int relay4 = 29;
int relay5 = 31;
int relay6 = 33;
int relay7 = 35;
int relay8 = 37;
int sw1Status, sw2Status, sw3Status, sw4Status;
int order = 1; //default is to set relays1 on .
int counter=0; //add exp
int sw1PushCounter = 1; // counter for the number of button presses
///int sw2Status = 0; // current state of the button
int lastsw1Status = 1; // previous state of the button
int sw2PushCounter = 1; // counter for the number of button presses
///int sw2Status = 0; // current state of the button
int lastsw2Status = 1; // previous state of the button
int sw3PushCounter = 1; // counter for the number of button presses
///int sw3Status = 0; // current state of the button
int lastsw3Status = 1; // previous state of the button
int sw4PushCounter = 1; // counter for the number of button presses
///int sw4Status = 0; // current state of the button
int lastsw4Status = 1; // previous state of the button
int count = 0;
int start;
int tool;
//// ///////for counter ////////////////////////////////////////////////
void setup() {
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(relay5, OUTPUT);
pinMode(relay6, OUTPUT);
pinMode(relay7, OUTPUT);
pinMode(relay8, OUTPUT);
// input pull-up, so default state of buttons is HIGH.
pinMode(sw1, INPUT_PULLUP);
pinMode(sw2, INPUT_PULLUP);
pinMode(sw3, INPUT_PULLUP);
pinMode(sw4, INPUT_PULLUP);
///pinMode(mode, INPUT_PULLUP);
///pinMode(start, INPUT_PULLUP);
///pinMode(tool, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
// read the buttons status
sw1Status = digitalRead(sw1);
sw2Status = digitalRead(sw2);
sw3Status = digitalRead(sw3);
sw4Status = digitalRead(sw4);
///////////////////////////////////////////////////////////////////////////////////////////
///modeState = digitalRead(mode);
///startState = digitalRead(start);
///toolState = digitalRead(tool);
/////if (sw1Status == LOW && sw2Status == HIGH && sw3Status == LOW && sw4Status == LOW && toolState == HIGH) {
//////////////////////////////////////////////////////////////////////////////////////////////
if (sw1Status == LOW && sw2Status == HIGH && sw3Status == LOW && sw4Status == LOW) {order = 2;
Serial.println("order2 sw2 & rly 2 on");}
///////////////////////////////////////////////////////////////// RIGHT Working
if (sw1Status == LOW && sw2Status == HIGH && sw3Status == HIGH && sw4Status == LOW){order = 3;
Serial.println(" order3 right side move down rly 1/7/8");
if (sw2Status != lastsw2Status){if (sw2Status == HIGH){sw2PushCounter++; if (sw2PushCounter > 0){order = 4;
{sw2PushCounter=0;
Serial.println("order4 repeat move right"); }}}}}
delay(500); //added delay
//////////////////////////////////////////////////////////////// LEFT not working
if (sw1Status == LOW && sw2Status == HIGH && sw3Status == LOW && sw4Status == HIGH){order = 3;
Serial.println("order3 left side sw2/4 move down rly1/7/8");
delay(800);
if (sw2Status != lastsw2Status){if (sw2Status == HIGH){sw2PushCounter++; if (sw2PushCounter > 0){order = 2;
{sw2PushCounter=0; sw1PushCounter=0;
Serial.println("order2 repeat move left rly 2"); } }}}}
////////////////////////////////////////////////////////////////////////////
if (sw1Status == HIGH && sw2Status == LOW && sw3Status == LOW && sw4Status == HIGH) {order = 5; //
Serial.println("orde7 left side move up "); }
delay(1200);
if (sw1Status == HIGH && sw2Status == LOW && sw3Status == HIGH && sw4Status == LOW) {order = 5; // changed 1
Serial.println("orde1 right side move up "); }
///////////////////////////////////////////////////////////////
if (sw1Status == LOW
&& sw2Status == LOW && sw3Status == HIGH && sw4Status == LOW) {order = 1;
Serial.println("orde6 sw3 H right side move up "); }
if (sw1Status == HIGH && sw2Status == LOW && sw3Status == LOW && sw4Status == LOW) {order = 1;
Serial.println("orde6 sw1 H fault position "); }
if (sw1Status == LOW && sw2Status == LOW && sw3Status == LOW && sw4Status == LOW) {if (order != 4) {
Serial.println("all switch off follow order 5");
order = 1;
} else { order = 1; }}
////////////////////////////////////////////////////////////////
lastsw1Status = sw1Status;
lastsw2Status = sw2Status;
lastsw3Status = sw3Status;
lastsw4Status = sw4Status;
switch (order) {
case 1: // if order equals 1
delay(500);
digitalWrite(relay1, LOW); //up
digitalWrite(relay2, HIGH);
digitalWrite(relay3, LOW); //magnet on
digitalWrite(relay4, LOW); //magnet on
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, HIGH);
digitalWrite(relay8, HIGH);
Serial.println("default start up magnet on ");
break;
case 2: // if order equals 2
delay(500);
digitalWrite(relay1, HIGH);
digitalWrite(relay2, LOW); //right
digitalWrite(relay3, LOW); //magnet on
digitalWrite(relay4, LOW); //magnet on
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, HIGH);
digitalWrite(relay8, HIGH);
Serial.println("move right magnet on case 2");
break;
case 3: // if order equals 3
delay(500);
digitalWrite(relay1, LOW); //power to rly 7,8
digitalWrite(relay2, HIGH);
digitalWrite(relay3, LOW); //magnet on
digitalWrite(relay4, LOW); //magnet on
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, LOW); //down
digitalWrite(relay8, LOW); //down
Serial.println("move down magnet on case 3");
break;
case 4: // if order equals 4
delay(700);
digitalWrite(relay1, LOW); //up
digitalWrite(relay2, LOW); //power to rly 5,6
digitalWrite(relay3, LOW); //magnet on
digitalWrite(relay4, LOW); //magnet on
digitalWrite(relay5, LOW); //left
digitalWrite(relay6, LOW); //left
digitalWrite(relay7, HIGH);
digitalWrite(relay8, HIGH);
Serial.println("move right to left magnet on case 4");
break;
case 5: // if order equals 5
delay(300);
digitalWrite(relay1, LOW); // up magnet off
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, HIGH);
digitalWrite(relay8, HIGH);
Serial.println("move up fail safe case 5");
break;
delay(300);
default: // if none of above cases is valid go to case 1
order = 1;
break;}
}