
gleasontech (Customer) asked a question.
still having trouble with a fault window, if sensor never gets found, I'm new to programming C++, my question is where to put the FAULTfatal flag if the timer goes to 60, the 3 second window has been exceeded, this code work if sensor found
still having trouble with a fault window, if sensor never gets found, I'm new to programming C++, my question is where to put the FAULTfatal flag if the timer goes to 60, then the 3 second window has been exceeded, this code work if sensor found,
- // **********************************************************************************
- // vacuum capture of sign sub routine- turn on vacuum and check for capture sign
- //
- int VACUUMcapture() {
- P1.writeDiscrete(HIGH,VACUUM); //vacuum generator solenoid 1=vacuum on / 0= vacuum off
- for (x = 0; x < 60; x ++) // fault timer 60*50mS = 3 second window or FAULTzone
- {
- VACUUMcaptureSIGN = P1.readDiscrete(VACUUMsignDETECT); //vacuum cup sign detection sensor 1=sign present / 0= not-sign present
- if (VACUUMcaptureSIGN == true ) { // exit loop on vacuum has captured sign sensor detected
- x = 0;
- break;
- return
- FAULTfatal = 1;
- }
- delay(50);
- // FAULTfatal = 1;
- }
- }
- // **********************************************************************************
You would want to put the fault fatal flag outside of the for loop. You also want to remove the break statement. Break will exit the for loop and then restart it after incrementing the variable x.
In the event that the vacuum sensor was detected you will want to just return which will exit the function. When the vacuum is undetected the for loop will execute fully and then the fault flag will be set.
Let me know if any of the explanation was unclear.
Thanks,
Kevin
I appreciate your help, I'm getting a error, it highlighting the return line
exit status 1
expected primary-expression before '}' token
I forgot the ";" after return.
also the function should be "void VACUUMcapture()" .
It looks like you are storing the flag as a global variable so you don't need to return the value.
THANK-YOU very much for the HELP, it worked well and all the sub notes/ comment very helpful !