Why do I say this? I just realized that the LED's in question are dimmer than normal when they are out of whack but normal intensity when they are deliberately activated. This leads me to believe that, as the processor runs through the loop it's toggling the relay rapidly. Low to high.
But, still, undoing the state of the LED would be preferred.
It would help us to help you if you post all your code. Many problems are caused by code outside of the immediate location of the snippet of code that are posted, as you have possibly found. Without the whole context of your code, you will not get the full benefit of people's help.
marco_c:
It would help us to help you if you post all your code. Many problems are caused by code outside of the immediate location of the snippet of code that are posted, as you have possibly found. Without the whole context of your code, you will not get the full benefit of people's help.
Yeah, I suppose I could post all 1609 lines of my code here for all to see, just to get a simple answer to a simple question that, apparently has no answer.
I'm not asking anyone to validate or scrutinize my code. I'm simply asking if there's an "undo" code for !LEDstate (the flip state of LEDstate).
If not then it's just that I have my code in the wrong places because setting LED_* to LOW isn't solving the issue.
As pointed out above, setting something LOW sets it LOW regardless of previous condition. So either the code isn't coming here and something else is setting it, or it does come here and something else in your logic sets it back again too quickly for you to see.
JimboZA:
As pointed out above, setting something LOW sets it LOW regardless of previous condition. So either the code isn't coming here and something else is setting it, or it does come here and something else in your logic sets it back again too quickly for you to see.
And that red part is what I was saying above when I said the LED was "dim". I thin my code is conflicting with itself.
When the code loops it basically is saying "turn LED ON" at one point in the code and "turn LED OFF" in another part. So basically as it loops it's modulating.
But, as I suspected, and is now verified, if I set it to LOW, it's LOW!
now I just have to stare at code long enough to find out why it's going back high...
now I just have to stare at code long enough to find out why it's going back high...
Yeah, that's going to work...
What you really need to do, is draw up a sheet with all the variables along the top, and walk through every step of code filling in the current value of each on a new line. then when you get to a branch in the code, perform the branch according to the values of the variables the logic looks at.
JimboZA:
That's why I suggested the Serial.print to see if the logic actually ever took you there...
EDIT.... I was also starting to wonder about all the brackets
Adding a serial print tutorial to my noggin just isn't a good idea at the moment. It would take me time and brain power and probably add confusion at this point.
Someday, soon, I will be ready to tackle that one and look back and see all the time I was wasting. But today isn't the day.
I'm pretty sure you want to: Read the value of BTN_01 and compare it to the value LOW.
To achieve this you need to put the comparison on the outside of the function call, otherwise you only read pin 0 or 1*, not BTN_01 or BTN_05 due to the way boolean values translate to integers.
digitalRead( BTN_01 ) == LOW
True values are anything other than zero, so it may not be 1, and could be regarded as possibly random.
see all the time I was wasting. But today isn't the day.
So, all those brackets? Elaborate, please.
No, that would be time I'm wasting and today isn't the day.
Edit.... but I see pYro has explained anyway.
Have you never used Serial print before?- fundamental debugging tool.
Put Serial.begin(9600); in setup(), then add the Serial.println("Boo"); line I suggested... upload the code, start the IDE monitor with ctl+shift+m and do whatever you expect takes you to that point. See if the monitor prints "boo". If not the logic didn't work....
see all the time I was wasting. But today isn't the day.
So, all those brackets? Elaborate, please.
No, that would be time I'm wasting and today isn't the day.
Edit.... but I see pYro has explained anyway.
Have you never used Serial print before?- fundamental debugging tool.
Put Serial.begin(9600); in setup(), then add the Serial.println("Boo"); line I suggested... upload the code, start the IDE monitor with ctl+shift+m and do whatever you expect takes you to that point. See if the monitor prints "boo". If not the logic didn't work....
Thanks.
I had a feeling you knew what was hanging me up but were just not willing to point it out.
Bittsen:
I had a feeling you knew what was hanging me up but were just not willing to point it out.
Not true.
I suggested the debug prints early on, since it seemed possible or even likely that the flow wan't actually going there, for whatever reason. I did point that out, that was a hunch, more than anything.
Then it struck me that the brackets looked wrong round about the time someone else did. I was however reluctant to waste my further time when you thought that implementing my previous suggestion was wasting yours. But as it happens the bracket thing was being explained in another post at the same time.
Waste your time by all means- just don't waste mine.
OK, so just adding "Serial.begin(9600);" to the setup screwed up the function of the whole sketch.
Adding the Serial.println("Boo"); screwed things up even more.
The code compiles correctly but when I run it on the Arduino it has a ton of unfavorable results.