Mbed OS Reference
Loading...
Searching...
No Matches
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.
 
 InterruptIn (PinName pin, PinMode mode)
 Create an InterruptIn connected to the specified pin, and the pin configured to the specified mode.
 
int read ()
 Read the input, represented as 0 or 1 (int)
 
 operator int ()
 An operator shorthand for read()
 
void rise (Callback< void()> func)
 Attach a function to call when a rising edge occurs on the input Interrupts are enabled for the pin.
 
void fall (Callback< void()> func)
 Attach a function to call when a falling edge occurs on the input Interrupts are enabled for the pin.
 
void mode (PinMode pull)
 Set the input pin mode.
 
void enable_irq ()
 Enable IRQ.
 
void disable_irq ()
 Disable IRQ.
 

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;
ThisThread::sleep_for(250);
}
}
A digital output, used for setting the state of a pin.
Definition DigitalOut.h:55
A digital interrupt input, used to call a function on a rising or falling edge.
Definition InterruptIn.h:65

Definition at line 65 of file InterruptIn.h.

Constructor & Destructor Documentation

◆ InterruptIn() [1/2]

InterruptIn ( PinName  pin)

Create an InterruptIn connected to the specified pin.

Parameters
pinInterruptIn pin to connect to

◆ InterruptIn() [2/2]

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

◆ 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

◆ operator int()

operator int ( )

An operator shorthand for read()

◆ rise()

void rise ( Callback< void()>  func)

Attach a function to call when a rising edge occurs on the input Interrupts are enabled for the pin.

Parameters
funcA pointer to a void function, or 0 to set as none

◆ fall()

void fall ( Callback< void()>  func)

Attach a function to call when a falling edge occurs on the input Interrupts are enabled for the pin.

Parameters
funcA pointer to a void function, or 0 to set as none

◆ mode()

void mode ( PinMode  pull)

Set the input pin mode.

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

◆ enable_irq()

void enable_irq ( )

Enable IRQ.

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

◆ disable_irq()

void disable_irq ( )

Disable IRQ.

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