if (ContainerLSWState == HIGH){
CCPM = millis();
}
if (millis() - CCPM == CCI){
PickedupSeq();
}
if (ContainerLSWState == LOW) {
COPM = millis();
}
if (millis() - COPM == COI){
ReturnSeq();
}
I have the above code that is acting weird. When my ContainerLSWState is HIGH, the code runs ReturnSeq(); function, and vice versa.
My agenda is to see the switch status, if its high or low, wait for 5 secs and then run the following funtion once only.
Thats the funny part, the code only runs once. So whats happening with this code is:
when the status turns HIGH, after 5 seconds, the ReturnsSeq(); functions runs once. and then thats it. now the code waits for the next change of state.
here is a code:
I dont see why posting the whole code will help. there is some proprietary information that cannot be share. The main loop is already posted above, there is nothing more to it.
Then go to your proprietors and explain to them that you need professional help. And they’ll probably have to pay for it.
This is a forum for beginners, hobbyists, dilettantes and the like.
If you can’t share information critical to solving you problem, we cannot help. If you cannot see why we ask for the things we do you are in over your head.
The problem is undoubtedly most likely to be found in the code you refuse to expose.
Well if you had the decency to pay attention to the code instead of complaining about sharing the whole code, you would have found the problem in there. I already got a private message from another member explaining what is going on with the code and why i am seeing what i am!
As i mentioned in my above post, there is nothing more in the loop.. that was it.. everything else was just communication modules for server access.
For all those who paid attention to the code and want to find the problem:
The problem was simple, not to my eyes unfortunately. But when the status of the switch changed, for example from Low to High, the if statement checking for the low state had the millis value retained, and that ran the 5sec timer and ran the returnseq(); function.
The standard approach to this situation is to write an MRE, Minimal Reproducible Example. That gives people a fair chance to fully understand and sometimes also test the code.
The problem with not posting a complete program, is that there are usually dependencies, such as data type declarations, that shouldn't be assumed. Also the side effects of the hidden code that may influence the revealed code are essentially limitless.
Maybe. Anyway, sorry, truly. I will add indecent and inattentive to the list of my character flaws.
My own ability to spot errors just by reading is limited, especially when there is no context. As @aarg has said, I am among those who will put more attention onto something complete, that I can run and tinker with…
And it is too bad the solution was PM delivered, thanks whoever that was, but s/he would have been more in the spirit of these fora to place those observations in line, publicly, for the benefit of all.
Understood. and I appreciate you putting it together the way you did.
I will surely keep that in mind posting any queries in the future in this forum or any other.