Updated

Committer:
noutram
Date:
Thu Jul 13 14:48:28 2017 +0000
Revision:
1:e722a94df6b4
Parent:
0:24ccc6d0c391
updated for mbed-os 5.5

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 0:24ccc6d0c391 7 //Declare functions
noutram 0:24ccc6d0c391 8 void sw1FallingEdge();
noutram 0:24ccc6d0c391 9
noutram 0:24ccc6d0c391 10 //Global Objects
noutram 0:24ccc6d0c391 11 DigitalOut red_led(D7);
noutram 0:24ccc6d0c391 12 DigitalOut green_led(D5);
noutram 0:24ccc6d0c391 13 InterruptIn sw1(D4);
noutram 0:24ccc6d0c391 14
noutram 0:24ccc6d0c391 15 //Interrupt service routine for a rising edge (press)
noutram 0:24ccc6d0c391 16 void sw1FallingEdge() {
noutram 0:24ccc6d0c391 17 red_led = !red_led; //Toggle the LED
noutram 0:24ccc6d0c391 18 }
noutram 0:24ccc6d0c391 19
noutram 0:24ccc6d0c391 20 //Main - only has to initialise and sleep
noutram 0:24ccc6d0c391 21 int main() {
noutram 0:24ccc6d0c391 22 //Initial logging message
noutram 0:24ccc6d0c391 23 puts("START");
noutram 0:24ccc6d0c391 24 red_led = 0;
noutram 0:24ccc6d0c391 25 green_led = 1;
noutram 0:24ccc6d0c391 26
noutram 0:24ccc6d0c391 27 //Configure interrupts, wait for first rising edge
noutram 0:24ccc6d0c391 28 sw1.fall(&sw1FallingEdge);
noutram 0:24ccc6d0c391 29
noutram 0:24ccc6d0c391 30 //Main Polling Loop
noutram 0:24ccc6d0c391 31 while (true) {
noutram 0:24ccc6d0c391 32
noutram 0:24ccc6d0c391 33 //Put CPU back to sleep
noutram 0:24ccc6d0c391 34 sleep();
noutram 0:24ccc6d0c391 35
noutram 0:24ccc6d0c391 36 //You can ONLY reach this point if an ISR wakes the CPU
noutram 0:24ccc6d0c391 37 puts("ISR just woke the MPU");
noutram 0:24ccc6d0c391 38
noutram 0:24ccc6d0c391 39 } //end while
noutram 0:24ccc6d0c391 40
noutram 0:24ccc6d0c391 41 }