1 ms is excessive - somewhere between 10 and 100 us should be sufficient. Therefore a delay between pinMode(buttonPin, INPUT_PULLUP) and attachInterrupt(digitalPinToInterrupt(buttonPin), Button, FALLING) is essential if you want to avoid a spurious interrupt. The weak internal pullup needs time to charge the stray capacitance of the pin & button wiring to reach a valid logic '1' level. Also, I could be completely wrong in why this is happening, if so, please do let me know. Plus I'm curious to know whether there is a fix to this other than what I did. 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. To test this, in the interrupt function, I added an if statement that goes like this: if(millis() > 1) instead of my original someBoolean = true And what do you know, that actually solved the issue. 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. Unfortunately, for some reason, the interrupt gets triggered when the code starts to run, at the beginning. So when it is pressed, the pin goes low and the interrupt is triggered. In my project, I have an interrupt that runs off this button, FALLING. 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) ". I have an Arduino sketch that involves something like this.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |