Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions
InterruptIn Class Reference

A digital interrupt input, used to call a function on a rising or falling edge. More...

#include <InterruptIn.h>

Inheritance diagram for InterruptIn:
NonCopyable< InterruptIn >

Public Member Functions

 InterruptIn (PinName pin)
 Create an InterruptIn connected to the specified pin. More...
 
 InterruptIn (PinName pin, PinMode mode)
 Create an InterruptIn connected to the specified pin, and the pin configured to the specified mode. More...
 
int read ()
 Read the input, represented as 0 or 1 (int) More...
 
 operator int ()
 An operator shorthand for read() More...
 
void rise (Callback< void()> func)
 Attach a function to call when a rising edge occurs on the input. More...
 
template<typename T , typename M >
void rise (T *obj, M method)
 Attach a member function to call when a rising edge occurs on the input. More...
 
void fall (Callback< void()> func)
 Attach a function to call when a falling edge occurs on the input. More...
 
template<typename T , typename M >
void fall (T *obj, M method)
 Attach a member function to call when a falling edge occurs on the input. More...
 
void mode (PinMode pull)
 Set the input pin mode. More...
 
void enable_irq ()
 Enable IRQ. More...
 
void disable_irq ()
 Disable IRQ. More...
 

Detailed Description

A digital interrupt input, used to call a function on a rising or falling edge.

Note
Synchronization level: Interrupt safe

Example:

// Flash an LED while waiting for events
#include "mbed.h"
InterruptIn event(p16);
DigitalOut led(LED1);
void trigger() {
printf("triggered!\n");
}
int main() {
// register trigger() to be called upon the rising edge of event
event.rise(&trigger);
while(1) {
led = !led;
wait(0.25);
}
}

Definition at line 65 of file InterruptIn.h.

Constructor & Destructor Documentation

InterruptIn ( PinName  pin)

Create an InterruptIn connected to the specified pin.

Parameters
pinInterruptIn pin to connect to
InterruptIn ( PinName  pin,
PinMode  mode 
)

Create an InterruptIn connected to the specified pin, and the pin configured to the specified mode.

Parameters
pinInterruptIn pin to connect to
modeDesired Pin mode configuration. (Valid values could be PullNone, PullDown, PullUp and PullDefault. See PinNames.h for your target for definitions)

Member Function Documentation

void disable_irq ( )

Disable IRQ.

This method depends on hardware implementation, might disable one port interrupts. For further information, check gpio_irq_disable().

void enable_irq ( )

Enable IRQ.

This method depends on hardware implementation, might enable one port interrupts. For further information, check gpio_irq_enable().

void fall ( Callback< void()>  func)

Attach a function to call when a falling edge occurs on the input.

Parameters
funcA pointer to a void function, or 0 to set as none
void fall ( T *  obj,
method 
)

Attach a member function to call when a falling edge occurs on the input.

Parameters
objpointer to the object to call the member function on
methodpointer to the member function to be called
Deprecated:
The rise function does not support cv-qualifiers. Replaced by rise(callback(obj, method)).

Definition at line 144 of file InterruptIn.h.

void mode ( PinMode  pull)

Set the input pin mode.

Parameters
pullPullUp, PullDown, PullNone, PullDefault See PinNames.h for your target for definitions)
operator int ( )

An operator shorthand for read()

int read ( )

Read the input, represented as 0 or 1 (int)

Returns
An integer representing the state of the input pin, 0 for logical 0, 1 for logical 1
void rise ( Callback< void()>  func)

Attach a function to call when a rising edge occurs on the input.

Parameters
funcA pointer to a void function, or 0 to set as none
void rise ( T *  obj,
method 
)

Attach a member function to call when a rising edge occurs on the input.

Parameters
objpointer to the object to call the member function on
methodpointer to the member function to be called
Deprecated:
The rise function does not support cv-qualifiers. Replaced by rise(callback(obj, method)).

Definition at line 119 of file InterruptIn.h.

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.