Hi
i wrote this code
the problem is that before i press the button the code loops as expected in ''loop function''
after i press it goes to the function i want and then after some time goes to an other function as was expected
the problem is that after i break from the last ''while loop'' goes again to ''loop funcrion'' as i wanted but doesnt loop there... goes again to the function as if i had press button again
i used and flags for button to solve that but something wrong with my code i suppose (maybe dont use them the right way)
here is the code :
byte lock_check = 13; // input pin to check lock-doors
byte contact_check = 14; // input pin to check contacts-doors
byte stop_check = 9; // input pin to check stop
byte end_limits = 2; // input pin to check end limits
byte relayLeft = 10; //the relay that drives left the car
byte relayRight = 11;//the relay that drives right the car
byte slowDownVVF = 12; // Pin to drive vvf voltage via transistor (slow speed)
byte electromagnet = 15; //the relay that drives up the electromagnet of doorslocks
byte call_button = 3; //pin to call to floor test for timelimits test
byte rstMvButton = 4; // reset time error in movement
unsigned long intervalMotor = 3000; // maximum working time
unsigned long previousMillisMotor;
bool callflag = false;
void setup() {
Serial.begin(9600);
// initialize the digital pins inputs.
pinMode(contact_check, INPUT_PULLUP);
pinMode(lock_check, INPUT_PULLUP);
pinMode(stop_check, INPUT_PULLUP);
pinMode(end_limits, INPUT_PULLUP);
pinMode(call_button, INPUT_PULLUP);
pinMode(rstMvButton, INPUT_PULLUP);
// initialize the digital pins outputs.
pinMode(relayRight, OUTPUT);
pinMode(relayLeft, OUTPUT);
pinMode(slowDownVVF, OUTPUT);
pinMode(electromagnet, OUTPUT);
}
void loop() {
boolean contacts;
boolean doorLocks;
boolean carStop;
boolean limitsStop;
boolean calling;
contacts = digitalRead(contact_check);
doorLocks = digitalRead(lock_check);
carStop = digitalRead(stop_check);
limitsStop = digitalRead(end_limits);
calling = digitalRead(call_button);
if (calling == false && callflag == false) {
if (contacts == false && carStop == false && limitsStop == false) {
callflag = true;
Run_Test();
}
}
if (contacts == false && carStop == false && limitsStop == false) {
Serial.println(" Everything ok - Standby ");
}
if (carStop == true) {
Serial.println(" Reads stop ");
}
if (contacts == true || carStop == true || limitsStop == true) {
digitalWrite(relayRight, LOW); //keep the relay for right motion inactive
digitalWrite(relayLeft, LOW); //keep the relay for left motion inactive
digitalWrite(slowDownVVF, LOW); //keep the VVF running with high speed quite
digitalWrite(electromagnet, LOW); //keep the relay for electromagnet inactive
}
if (carStop == true || limitsStop == true ) {
stop_car();
}
}
void Run_Test() {
boolean doorLocks;
boolean carStop;
boolean limitsStop;
boolean contacts;
previousMillisMotor = millis();
doorLocks = digitalRead(lock_check);
carStop = digitalRead(stop_check);
limitsStop = digitalRead(end_limits);
contacts = digitalRead(contact_check);
callflag = true;
if (contacts == false && carStop == false && limitsStop == false ) {
do
{
callflag = false;
doorLocks = digitalRead(lock_check);
carStop = digitalRead(stop_check);
limitsStop = digitalRead(end_limits);
contacts = digitalRead(contact_check);
digitalWrite(relayRight, HIGH);
Serial.println(" Going to position ");
if (millis() - previousMillisMotor >= intervalMotor)
{
timeError();
}
}
while ( contacts == false && carStop == false && limitsStop == false);
}
}
void stop_car() {
boolean carStop;
boolean limitsStop;
carStop = digitalRead(stop_check);
limitsStop = digitalRead(end_limits);
while (carStop == true ) {
boolean carStop;
carStop = digitalRead(stop_check);
digitalWrite(relayRight, LOW); //keep the relay for right motion inactive
digitalWrite(relayLeft, LOW); //keep the relay for left motion inactive
digitalWrite(slowDownVVF, LOW); //keep the VVF running with high speed quite
digitalWrite(electromagnet, LOW); //keep the relay for electromagnet inactive
Serial.println("Stop is Active");
if (carStop == !true ) {
break;
}
}
while (limitsStop == true ) {
boolean limitsStop;
limitsStop = digitalRead(end_limits);
digitalWrite(relayRight, LOW); //keep the relay for right motion inactive
digitalWrite(relayLeft, LOW); //keep the relay for left motion inactive
digitalWrite(slowDownVVF, LOW); //keep the VVF running with high speed quite
digitalWrite(electromagnet, LOW); //keep the relay for electromagnet inactive
Serial.println("end limits are on");
if (limitsStop == !true ) {
break;
}
}
}
void timeError() {
boolean resetMove;
resetMove = digitalRead(rstMvButton);
previousMillisMotor = millis();
do {
resetMove = digitalRead(rstMvButton);
Serial.println("To Late - Time Limit");
if (resetMove == false ) {
Serial.println("Reads resetbutton");
break;
}
} while (resetMove == true);
loop();
}
thanks in advance