Arduino_StateChangeDetection_Interrupt sample code ported.

Dependencies:   mbed

Fork of InterruptIn_HelloWorld by mbed official

Committer:
homayoun
Date:
Wed Sep 03 12:38:24 2014 +0000
Revision:
1:6c7f14195903
Parent:
0:7a20a6aa1f5e
Arduino_StateChangeDetection_Interrupt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:7a20a6aa1f5e 1 #include "mbed.h"
homayoun 1:6c7f14195903 2
homayoun 1:6c7f14195903 3 InterruptIn button(USER_BUTTON);
homayoun 1:6c7f14195903 4 Serial pc(SERIAL_TX, SERIAL_RX);
mbed_official 0:7a20a6aa1f5e 5 DigitalOut led(LED1);
homayoun 1:6c7f14195903 6 int buttonPushCounter = 0; // counter for the number of button presses
homayoun 1:6c7f14195903 7
homayoun 1:6c7f14195903 8 void buttonPressed()
homayoun 1:6c7f14195903 9 {
homayoun 1:6c7f14195903 10 buttonPushCounter++;
homayoun 1:6c7f14195903 11
homayoun 1:6c7f14195903 12 if (buttonPushCounter % 4 == 0) led = 1;
homayoun 1:6c7f14195903 13 else led = 0;
homayoun 1:6c7f14195903 14
homayoun 1:6c7f14195903 15 pc.printf("number of button pushes: %d.\n", buttonPushCounter);
homayoun 1:6c7f14195903 16 }
homayoun 1:6c7f14195903 17
homayoun 1:6c7f14195903 18 void buttonReleased()
homayoun 1:6c7f14195903 19 {
homayoun 1:6c7f14195903 20
mbed_official 0:7a20a6aa1f5e 21 }
homayoun 1:6c7f14195903 22
homayoun 1:6c7f14195903 23 void setup()
homayoun 1:6c7f14195903 24 {
homayoun 1:6c7f14195903 25 button.mode(PullUp);
homayoun 1:6c7f14195903 26 pc.baud(9600);
homayoun 1:6c7f14195903 27 button.rise(&buttonReleased); // attach the address of the buttonReleased function to the rising edge
homayoun 1:6c7f14195903 28 button.fall(&buttonPressed); // attach the address of the buttonPressed function to the falling edge
homayoun 1:6c7f14195903 29 }
homayoun 1:6c7f14195903 30
homayoun 1:6c7f14195903 31 void loop()
homayoun 1:6c7f14195903 32 {
homayoun 1:6c7f14195903 33 // put your main code here, to run repeatedly:
homayoun 1:6c7f14195903 34
homayoun 1:6c7f14195903 35 }
homayoun 1:6c7f14195903 36
homayoun 1:6c7f14195903 37 int main()
homayoun 1:6c7f14195903 38 {
homayoun 1:6c7f14195903 39 setup();
homayoun 1:6c7f14195903 40 while(1) loop();
mbed_official 0:7a20a6aa1f5e 41 }