homayoun mh / Mbed 2 deprecated Arduino_StateChangeDetection_Interrupt

Dependencies:   mbed

Fork of InterruptIn_HelloWorld by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 InterruptIn button(USER_BUTTON);
00004 Serial pc(SERIAL_TX, SERIAL_RX);
00005 DigitalOut led(LED1);
00006 int buttonPushCounter = 0;   // counter for the number of button presses
00007 
00008 void buttonPressed()
00009 {  
00010     buttonPushCounter++;
00011     
00012     if (buttonPushCounter % 4 == 0) led = 1;
00013     else led = 0;
00014     
00015     pc.printf("number of button pushes: %d.\n", buttonPushCounter);
00016 }
00017 
00018 void buttonReleased()
00019 {
00020     
00021 }
00022 
00023 void setup()
00024 {
00025     button.mode(PullUp);
00026     pc.baud(9600);
00027     button.rise(&buttonReleased);  // attach the address of the buttonReleased function to the rising edge
00028     button.fall(&buttonPressed);  // attach the address of the buttonPressed function to the falling edge
00029 }
00030 
00031 void loop()
00032 {
00033     // put your main code here, to run repeatedly:
00034 
00035 }
00036 
00037 int main()
00038 {
00039     setup();
00040     while(1) loop();
00041 }