Basic Library
Digital I/O
Analog I/O
Advanced I/O
Time
Math
Trigonometry
Random Numbers
Bits and Bytes
Interrupts
Communication
Standard Library
Servo Motor
Stepper
Liquid Crystal
EEPROM
SPI
I2C (Wire)
SD Card
SD Card (File Control)
Ethernet
Ethernet (Server)
Ethernet (Client)
Firmata
Periodic Operation
Power Save
Clock (RTC)
SoftwareSerial
Utility
Interrupt
This library is for using an interrupt operation from specified pins.
GR-ADZUKI has a 2 button switch on pin 2 and pin 3. You can utilize these buttons to use interrupt.
attachInterrupt
Description
Specifies a function to call when an external interrupt occurs. Replaces any previous function that was attached to the interrupt. The board has two external interrupts: number 0 (on pin2), 1 (on pin3) and 2 (on pin25). The function to call has no parameter and no return.
Syntax
attachInterrupt(unsigned char interrupt, void(*)(void) func, int mode)
Parameters
interrupt: Specify interrupt number 0(pin2), 1(pin3) or 2(pin25)
function: Specify the function to call when interrupt occurs; this function must take no parameters and return nothing. This function is sometimes referred to as an interrupt service routine.
mode: CHANGE (whenever the pin changes value), FALLING (when the pin goes from high to low), RISING (when the pin goes from low to high)Returns
None
Remarks
LOW cannot be specified to mode. In the case of specifying LOW, CHANGE is specified.
The functions used by the system are not executed during interrupt operating; as a result, delay(), millis(), Serial() do not work well. Then try interrupts() in interrupt.
detachInterrupt
Description
Turns off the given interrupt.
Syntax
detachInterrupt(unsigned char interrupt)
Parameters
interrupt: The number of the interrupt to disable (0 or 1 or 2)
Returns
None
interrupts
Description
Re-enables interrupts (after they've been disabled by noInterrupts()).
Syntax
interrupts()
Parameters
None
Returns
None
noInterrupts
Description
Disables interrupts (you can re-enable them with interrupts()). Interrupts allow certain important tasks to happen in the background and are enabled by default. Some functions will not work while interrupts are disabled, and incoming communication may be ignored. Interrupts can slightly disrupt the timing of code, however, and may be disabled for particularly critical sections of code.
Syntax
noInterrupts()
Parameters
None
Returns
None
Example
LED lights up when the button on GR-ADZUKI is pushed.
#include <Arduino.h>
void sw1_push(){
digitalWrite(12, HIGH);
delayMicroseconds(100000); // 100ms
digitalWrite(12, LOW);
}
void sw2_push(){
digitalWrite(13, HIGH);
delayMicroseconds(100000); // 100ms
digitalWrite(13, LOW);
}
void setup() {
pinMode(3, INPUT_PULLUP); // for sw1
pinMode(2, INPUT_PULLUP); // for sw2
attachInterrupt(1, sw1_push, FALLING);
attachInterrupt(0, sw2_push, FALLING);
pinMode(12, OUTPUT);
digitalWrite(12, LOW);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
}
void loop() {
}