Name

noInterrupts()

Class

GPIO

Description

Prevents interrupts from happpening

You can use noInterrupts() and interrupts() in tandem to make sure no interrupts are occuring while your sketch is doing a particular task.
br/> While a method associated with a pin's interrupt is being executed, interrupts from the same pin are automatically prevented from occurring. Interrupts from other pins can still happen, however. If you also want to prevent those, put noInterrupts() at the beginning of your callback function and interrupts() at its end.

Examples

  • import processing.io.*;
    color bgcolor = 0;
    
    void setup() {
      GPIO.pinMode(4, GPIO.INPUT);
      GPIO.pinMode(5, GPIO.INPUT);
      GPIO.attachInterrupt(4, this, "pinEvent", GPIO.RISING);
      GPIO.attachInterrupt(5, this, "pinEvent", GPIO.RISING);
    }
    
    void draw() {
      background(bgcolor);
    }
    
    void pinEvent(int pin) {
      GPIO.noInterrupts();
      // no other interrupt will disturb us
      println("Received interrupt on pin" + pin);
      if (bgcolor == 0) {
        bgcolor = color(255);
      } else {
        bgcolor = color(0);
      }
      GPIO.interrupts();
    }
    
    

Syntax

  • .noInterrupts()

Return

  • void