I don't understand why the LED won't blink until I let go of the button, (making the while loop false.) Would it not continue to blink the LED until the while loop becomes false?
I see. I'm just trying to understand other people's code so I can implement their pieces into mine.
I think I understand it now though...
The while loop will continue to check the button's value once it is low. But when you let go to make it high, the while loop stops and it executes the blinks.
Ah, okay. Thank you, your help is much appreciated!
Agreed, I thought this was an interesting workaround for the debounce and button press issue I had earlier. But, I suppose it's best for the long term to stay conventional.
Hi,
How have you got your button wired?
1.Between digital input and gnd. OR
2. Between digital input and 5V
If 1. Have you got a 10K pullup resistor between the digital input and 5V?
If 2. Have you got a 10K pulldown resistor between the digital input and gnd?
But I don't believe there is a sequence point in that expression that guarantees the preincrement completes before the assignment. But again, I am NOT a standards expert guy.
preincrement means exactly what you think, you add 1 to the variable before using said value. It also stores this incremented value back into the original location. The assignment operator also stores a value back into the same location. You now have two writes to the same memory location and no guarantee about which one will happen first. Just because the arduino code does the right thing, does not mean it doesn't fall into the undefined behavior category.
So let’s don’t learn from you all about this confusing matter you bring up.
google out of curiosity, I found this
i = ++i + 2; // undefined behavior until C++11
I tend to have trouble learning about these things, so I’m just as happy to write things like that out as a few statements. Clearer for every body, no disagreements.