Updated for mbed-os 2019

Committer:
noutram
Date:
Thu Sep 12 13:56:16 2019 +0000
Revision:
3:9a3c6c16dc25
Parent:
0:24ccc6d0c391
2019

Who changed what in which revision?

UserRevisionLine numberNew contents of line
noutram 0:24ccc6d0c391 1 #include "mbed.h"
noutram 0:24ccc6d0c391 2
noutram 0:24ccc6d0c391 3 // This uses INTERRUPTS to detect a falling edge of the switch input
noutram 0:24ccc6d0c391 4 // However, pressing and releasing the switch can result in spurious falling edges
noutram 0:24ccc6d0c391 5 // which trigger the routine
noutram 0:24ccc6d0c391 6
noutram 3:9a3c6c16dc25 7 //Uncomment this if you want to use the onboard LEDs and Blue Switch on a F429ZI
noutram 3:9a3c6c16dc25 8 //#define USEONBOARD
noutram 3:9a3c6c16dc25 9
noutram 0:24ccc6d0c391 10 //Declare functions
noutram 0:24ccc6d0c391 11 void sw1FallingEdge();
noutram 0:24ccc6d0c391 12
noutram 0:24ccc6d0c391 13 //Global Objects
noutram 3:9a3c6c16dc25 14 #ifdef USEONBOARD
noutram 3:9a3c6c16dc25 15 DigitalOut red_led(LED3);
noutram 3:9a3c6c16dc25 16 DigitalOut green_led(LED1);
noutram 3:9a3c6c16dc25 17 InterruptIn sw1(USER_BUTTON);
noutram 3:9a3c6c16dc25 18 #else
noutram 0:24ccc6d0c391 19 DigitalOut red_led(D7);
noutram 0:24ccc6d0c391 20 DigitalOut green_led(D5);
noutram 3:9a3c6c16dc25 21 InterruptIn sw1(D4);
noutram 3:9a3c6c16dc25 22 #endif
noutram 0:24ccc6d0c391 23
noutram 0:24ccc6d0c391 24 //Interrupt service routine for a rising edge (press)
noutram 0:24ccc6d0c391 25 void sw1FallingEdge() {
noutram 0:24ccc6d0c391 26 red_led = !red_led; //Toggle the LED
noutram 0:24ccc6d0c391 27 }
noutram 0:24ccc6d0c391 28
noutram 3:9a3c6c16dc25 29 Serial pc(USBTX, USBRX);
noutram 3:9a3c6c16dc25 30
noutram 0:24ccc6d0c391 31 //Main - only has to initialise and sleep
noutram 0:24ccc6d0c391 32 int main() {
noutram 3:9a3c6c16dc25 33
noutram 3:9a3c6c16dc25 34 pc.set_blocking(true);
noutram 0:24ccc6d0c391 35 red_led = 0;
noutram 0:24ccc6d0c391 36 green_led = 1;
noutram 0:24ccc6d0c391 37
noutram 0:24ccc6d0c391 38 //Configure interrupts, wait for first rising edge
noutram 0:24ccc6d0c391 39 sw1.fall(&sw1FallingEdge);
noutram 0:24ccc6d0c391 40
noutram 0:24ccc6d0c391 41 //Main Polling Loop
noutram 0:24ccc6d0c391 42 while (true) {
noutram 0:24ccc6d0c391 43
noutram 0:24ccc6d0c391 44 //Put CPU back to sleep
noutram 0:24ccc6d0c391 45 sleep();
noutram 0:24ccc6d0c391 46
noutram 0:24ccc6d0c391 47 //You can ONLY reach this point if an ISR wakes the CPU
noutram 3:9a3c6c16dc25 48 green_led = !green_led;
noutram 3:9a3c6c16dc25 49
noutram 3:9a3c6c16dc25 50 //Any use of the serial port will produce a series of interrupts
noutram 3:9a3c6c16dc25 51 //pc.puts("Ping!\n\r");
noutram 0:24ccc6d0c391 52
noutram 0:24ccc6d0c391 53 } //end while
noutram 0:24ccc6d0c391 54
noutram 0:24ccc6d0c391 55 }