I have an Arduino sketch that involves something like this. There is a button, and because I'm too lazy to create a voltage divider by adding an extra resistor at the breadboard, I just did "pinMode(buttonPin, INPUT_PULLUP);". Easy peasy. In my project, I have an interrupt that runs off this button, FALLING. So when it is pressed, the pin goes low and the interrupt is triggered. Unfortunately, for some reason, the interrupt gets triggered when the code starts to run, at the beginning. Thinking about this with my noob reasoning, I can only conclude that the interrupt runs even before the part that makes the button pin an INPUT_PULLUP, therefore triggering it falsely.
To test this, in the interrupt function, I added an if statement that goes like this:
if(millis() > 1)
{
someBoolean = true;
}
instead of my original
someBoolean = true;
And what do you know, that actually solved the issue. Now, I could just leave this as it is, but I don't like leaving a part of the code and commenting that I don't understand why it has to be there. Plus I'm curious to know whether there is a fix to this other than what I did. Also, I could be completely wrong in why this is happening, if so, please do let me know.