Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of InterruptIn_HelloWorld by
Revision 1:6c7f14195903, committed 2014-09-03
- Comitter:
- homayoun
- Date:
- Wed Sep 03 12:38:24 2014 +0000
- Parent:
- 0:7a20a6aa1f5e
- Commit message:
- Arduino_StateChangeDetection_Interrupt
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Feb 15 15:13:19 2013 +0000
+++ b/main.cpp Wed Sep 03 12:38:24 2014 +0000
@@ -1,17 +1,41 @@
#include "mbed.h"
-
-InterruptIn button(p5);
+
+InterruptIn button(USER_BUTTON);
+Serial pc(SERIAL_TX, SERIAL_RX);
DigitalOut led(LED1);
-DigitalOut flash(LED4);
-
-void flip() {
- led = !led;
+int buttonPushCounter = 0; // counter for the number of button presses
+
+void buttonPressed()
+{
+ buttonPushCounter++;
+
+ if (buttonPushCounter % 4 == 0) led = 1;
+ else led = 0;
+
+ pc.printf("number of button pushes: %d.\n", buttonPushCounter);
+}
+
+void buttonReleased()
+{
+
}
-
-int main() {
- button.rise(&flip); // attach the address of the flip function to the rising edge
- while(1) { // wait around, interrupts will interrupt this!
- flash = !flash;
- wait(0.25);
- }
+
+void setup()
+{
+ button.mode(PullUp);
+ pc.baud(9600);
+ button.rise(&buttonReleased); // attach the address of the buttonReleased function to the rising edge
+ button.fall(&buttonPressed); // attach the address of the buttonPressed function to the falling edge
+}
+
+void loop()
+{
+ // put your main code here, to run repeatedly:
+
+}
+
+int main()
+{
+ setup();
+ while(1) loop();
}
\ No newline at end of file
--- a/mbed.bld Fri Feb 15 15:13:19 2013 +0000 +++ b/mbed.bld Wed Sep 03 12:38:24 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/0954ebd79f59 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013 \ No newline at end of file
