Lab version

Fork of Task326 by Nicholas Outram

Files at this revision

API Documentation at this revision

Comitter:
noutram
Date:
Thu Sep 12 14:47:03 2019 +0000
Parent:
1:a20f07949275
Commit message:
2019

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Jul 13 14:48:54 2017 +0000
+++ b/main.cpp	Thu Sep 12 14:47:03 2019 +0000
@@ -1,5 +1,10 @@
 #include "mbed.h"
 
+#ifdef TARGET_NUCLEO_F429ZI
+//Uncomment the following line to use onboard LEDs and Switch (F429ZI only)
+//#define USEONBOARD
+#endif
+
 //A slight improvement - however, the pressing of the switch still registers
 //spurious falling edges!
 
@@ -11,21 +16,30 @@
 #define EDGE_FALLEN 0
 
 //Global Objects
+#ifdef USEONBOARD
+DigitalOut  red_led(LED3);
+DigitalOut  green_led(LED1);
+InterruptIn   sw1(USER_BUTTON);
+#else
 DigitalOut  red_led(D7);
 DigitalOut  green_led(D5);
 InterruptIn   sw1(D4);
-InterruptIn   sw2(D3);
+#endif
 
 Timeout sw1TimeOut;             //Used to prevent switch bounce
+bool timerFired = false;
+bool switchPressed = false;
 
 //Interrupt service routine for handling the timeout
 void sw1TimeOutHandler() {
+    timerFired = true;
     sw1TimeOut.detach();        //Stop the timeout counter firing
     sw1.fall(&sw1FallingEdge);  //Now wait for a falling edge
 }
 
 //Interrupt service routive for SW1 falling edge (release)
 void sw1FallingEdge() {
+    switchPressed = true;
     sw1.fall(NULL);                             //Disable this interrupt
     red_led = !red_led;                         //Toggle LED    
     sw1TimeOut.attach(&sw1TimeOutHandler, 0.2); //Start timeout counter    
@@ -33,8 +47,6 @@
 
 //Main - only has to initialise and sleep
 int main() {
-    //Initial logging message
-    puts("START");
     
     //Initial state
     red_led    = 0; //Set RED LED to OFF
@@ -49,9 +61,14 @@
         //Put CPU back to sleep
         sleep();
         
-        //You can ONLY reach this point if an ISR wakes the CPU
-        puts("ISR just woke the MPU");
-        
+        //You can ONLY reach this point if an ISR wakes the CPU - now there are two
+        if (timerFired == true) {
+            timerFired = false;        //Reset flag
+        }
+        if (switchPressed == true) {
+            switchPressed = false;      //Reset flag
+            green_led = !green_led;
+        }
     } //end while
 
 }
--- a/mbed-os.lib	Thu Jul 13 14:48:54 2017 +0000
+++ b/mbed-os.lib	Thu Sep 12 14:47:03 2019 +0000
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#8828635da469162cf2854b5287561c663fb96e72
+https://github.com/ARMmbed/mbed-os/#1bf6b20df9d3cd5f29f001ffc6f0d0fcbbb96118
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Thu Sep 12 14:47:03 2019 +0000
@@ -0,0 +1,3 @@
+{
+    "requires": ["bare-metal"]
+}
\ No newline at end of file