The best way is to use a global variable to notify the main code that an interrupt has occurred, then verify and clear that flag within the loop() and execute instructions. The ISR function should be as minimal as feasible so that the processor can swiftly return to the main program’s execution. The name of the function that will be called every time the interrupt is caused – the interrupt service routine – is the second argument of the attachInterrupt() function (ISR). The ESP8266 supports interrupts in any GPIO, except GPIO16. For example, if you want to use GPIO 14 as an interrupt, use: digitalPinToInterrupt(14) You should use digitalPinToInterrupt(GPIO) to set the actual GPIO as an interrupt pin. To set an interrupt in the Arduino IDE, you use the attachInterrupt() function, which accepts as arguments: the GPIO interrupt pin, the name of the function to be executed, and mode: attachInterrupt(digitalPinToInterrupt(GPIO), ISR, mode) GPIO interrupt pin This is especially useful to trigger an action whenever motion is detected or whenever a pushbutton is pressed without the need to constantly check its state. When an interrupt occurs, the CPU interrupts the main programme to do a task before returning to the main programme, as indicated in the diagram below. The interrupt service procedure is the name of this function (ISR). An event is triggered - a function is called – when a change is noticed. You don’t have to keep checking the current pin value with interrupts. Interrupts are useful in microcontroller applications for making things happen automatically and for resolving timing issues.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |