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.
Revision 6:52f9ba83203c, committed 2020-01-24
- Comitter:
- eencae
- Date:
- Fri Jan 24 12:07:07 2020 +0000
- Parent:
- 5:d5bdf787ae1a
- Commit message:
- Updated for Gamepad2;
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 Wed Dec 20 09:54:28 2017 +0000 +++ b/main.cpp Fri Jan 24 12:07:07 2020 +0000 @@ -7,43 +7,45 @@ Demonstrates how to use InterruptIn to generate an event-triggered interrupt (c) Craig A. Evans, University of Leeds, Jan 2016 +Updated January 2020 */ #include "mbed.h" -// Create objects for SW2 (right switch) and red LED -InterruptIn sw2(SW2); -DigitalOut red_led(LED_RED); +// Create objects for button and LED +InterruptIn buttonA(PTC7); +DigitalOut led1(PTA2); // flag - must be volatile as changes within ISR // g_ prefix makes it easier to distinguish it as global -volatile int g_sw2_flag = 0; +volatile int g_buttonA_flag = 0; // function prototypes -void sw2_isr(); +void buttonA_isr(); int main() { - // SW2 has a pull-up resistor, so the pin will be at 3.3 V by default - // and fall to 0 V when pressed. We therefore need to look for a falling edge - // on the pin to fire the interrupt - sw2.fall(&sw2_isr); - // since SW2 has an external pull-up, we should disable to internal pull-down - // resistor that is enabled by default using InterruptIn - sw2.mode(PullNone); - // the on-board RGB LED is a common anode - writing a 1 to the pin will turn the LED OFF - red_led = 1; + buttonA.mode(PullUp); // turn on internal pull-up resistor + // pin will be 1 (3.3 V) when not pressed and 0 (0 V) when pressed + + // We therefore need to look for a falling edge on the pin to fire the interrupt + // when the button is pressed + buttonA.fall(&buttonA_isr); + + // the LED is a common anode - writing a 1 to the pin will turn the LED OFF + led1 = 1; while (1) { // check if flag i.e. interrupt has occured - if (g_sw2_flag) { - g_sw2_flag = 0; // if it has, clear the flag + if (g_buttonA_flag) { + g_buttonA_flag = 0; // if it has, clear the flag // send message over serial port - can observe in CoolTerm etc. printf("Execute task \n"); - // DO TASK HERE + + led1 = !led1; // toggle LED } // put the MCU to sleep until an interrupt wakes it up @@ -52,8 +54,8 @@ } } -// SW2 event-triggered interrupt -void sw2_isr() +// Button A event-triggered interrupt +void buttonA_isr() { - g_sw2_flag = 1; // set flag in ISR + g_buttonA_flag = 1; // set flag in ISR }
--- a/mbed.bld Wed Dec 20 09:54:28 2017 +0000 +++ b/mbed.bld Fri Jan 24 12:07:07 2020 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/e7ca05fa8600 \ No newline at end of file +https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc \ No newline at end of file