SOFT261 2018 May Coursework Power On Self Test application

Files at this revision

API Documentation at this revision

Comitter:
noutram
Date:
Tue May 01 09:05:02 2018 +0000
Parent:
2:c8dc7c4c7bda
Child:
4:3d7da70d57a1
Commit message:
Coming along :)

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
post_may18.cpp Show diff for this revision Revisions of this file
post_may18.hpp Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Apr 30 14:07:05 2018 +0000
+++ b/main.cpp	Tue May 01 09:05:02 2018 +0000
@@ -1,30 +1,120 @@
 #include "mbed.h"
-#include "post_may18.hpp"
 //
 // Coursework Template 1.0
 //
-// Please clone and edit as appropriate
+// Please clone and edit as appropriate. Please read comments below.
+//
+//
+// Function declarations
+void POST(); 
 
+//*****************************************************************************
+// 1. COMMENT OUT THIS LINE FOR YOUR OWN CODE
+#define SOFT261_MAY18_HARDWARE_CHECK
+// ****************************************************************************
 
-// CLONE THIS PROJECT FOR EACH TASK
-
-//Hardware declarations for the power-on self test.
+#ifdef SOFT261_MAY18_HARDWARE_CHECK
+//Hardware declarations for the full power-on self test.
+DigitalOut redLed(D7);
+DigitalOut yellowLed(D6);
+DigitalOut greenLed(D5);
+DigitalIn sw1(D4);
+DigitalIn sw2(D3);
+AnalogIn adcIn(A0);
+int main() { POST(); while (true); }
+#else
+// ****************************************************************************
+// 2. Declare your driver objects here - some are done for you
+// ****************************************************************************
 DigitalOut redLed(D7);
 DigitalOut yellowLed(D6);
 DigitalOut greenLed(D5);
-
-//Inputs
-DigitalIn sw1(D4);
-DigitalIn sw2(D3);
 AnalogIn adcIn(A0);
 
 
-// main() runs in its own thread in the OS - for this coursework, keep all code
-// in this single file.
+// ****************************************************************************
+// 3. Write task code here
+// ****************************************************************************
+    
+//Main function - your entry point and often main loop
 int main()
 {
-    POST(); //Power on self test - you may remove this line for your own project
-    
-    while (true) {}
+    POST(); //Power on self test - you can leave this here if you wish
+
+    //Infinite loop (you may remove if you wish)
+    while (true) {
+                
+    }
 }
+#endif
 
+
+
+
+
+
+
+
+// ***************************************************************************
+// No changes beyond this point
+// ***************************************************************************
+
+//
+// POWER ON SELF TEST (POST)
+#ifdef SOFT261_MAY18_HARDWARE_CHECK
+void POST() {
+    //Check serial interface is configured
+    puts("Checking serial communications with PuTTY");
+
+    //Check switches
+    puts("Press switches now");
+    wait(1.0);
+    int s1 = __sw1;
+    int s2 = __sw2;
+    printf("Switch 1 state = %s\n", (s1 == 1) ? "PRESSED" : "RELEASED");
+    printf("Switch 2 state = %s\n", (s2 == 1) ? "PRESSED" : "RELEASED");
+    puts("Release the switches");
+    wait(1.0);
+    s1 = __sw1;
+    s2 = __sw2;
+    printf("Switch 1 state = %s\n", (s1 == 1) ? "PRESSED" : "RELEASED");
+    printf("Switch 2 state = %s\n", (s2 == 1) ? "PRESSED" : "RELEASED");
+
+    //Check LEDs
+    puts("Checking LEDs");
+    for (unsigned int n=0; n<5; n++) {
+        puts("red");
+        __redLed    = 1;
+        __yellowLed = 0;
+        __greenLed  = 0;
+        wait(0.2);
+        puts("yellow");
+        __redLed    = 0;
+        __yellowLed = 1;
+        __greenLed  = 0;
+        wait(0.2);
+        puts("green");
+        __redLed    = 0;
+        __yellowLed = 0;
+        __greenLed  = 1;
+        wait(0.2);
+    }
+    //Check switches
+    __greenLed = 0;
+
+    //Finally the ADC
+    puts("Check ADC - turn potentiometer");
+    wait(1.0);
+    float v = __adcIn;
+    printf("vin = %.4f\n", v);
+    puts("Check ADC - turn potentiometer again");
+    wait(1.0);
+    v = __adcIn;
+    printf("vin = %.4f\n", v);
+    puts("DONE.");
+}
+#else
+void POST() {
+    puts("Checking serial communications with PuTTY");
+}
+#endif
\ No newline at end of file
--- a/post_may18.cpp	Mon Apr 30 14:07:05 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,72 +0,0 @@
-#include "post_may18.hpp"
-
-
-//
-// POWER ON SELF TEST (POST)
-#ifdef SOFT261_MAY18_HARDWARE_CHECK
-//Hardware declarations for the power-on self test.
-static DigitalOut __redLed(D7);
-static DigitalOut __yellowLed(D6);
-static DigitalOut __greenLed(D5);
-
-//Inputs
-static DigitalIn __sw1(D4);
-static DigitalIn __sw2(D3);
-static AnalogIn __adcIn(A0);
-
-void POST() {
-    //Check serial interface is configured
-    puts("Checking serial communications with PuTTY");
-
-    //Check switches
-    puts("Press switches now");
-    wait(1.0);
-    int s1 = __sw1;
-    int s2 = __sw2;
-    printf("Switch 1 state = %s\n", (s1 == 1) ? "PRESSED" : "RELEASED");
-    printf("Switch 2 state = %s\n", (s2 == 1) ? "PRESSED" : "RELEASED");
-    puts("Release the switches");
-    wait(1.0);
-    s1 = __sw1;
-    s2 = __sw2;
-    printf("Switch 1 state = %s\n", (s1 == 1) ? "PRESSED" : "RELEASED");
-    printf("Switch 2 state = %s\n", (s2 == 1) ? "PRESSED" : "RELEASED");
-
-    //Check LEDs
-    puts("Checking LEDs");
-    for (unsigned int n=0; n<5; n++) {
-        puts("red");
-        __redLed    = 1;
-        __yellowLed = 0;
-        __greenLed  = 0;
-        wait(0.2);
-        puts("yellow");
-        __redLed    = 0;
-        __yellowLed = 1;
-        __greenLed  = 0;
-        wait(0.2);
-        puts("green");
-        __redLed    = 0;
-        __yellowLed = 0;
-        __greenLed  = 1;
-        wait(0.2);
-    }
-    //Check switches
-    __greenLed = 0;
-
-    //Finally the ADC
-    puts("Check ADC - turn potentiometer");
-    wait(1.0);
-    float v = __adcIn;
-    printf("vin = %.4f\n", v);
-    puts("Check ADC - turn potentiometer again");
-    wait(1.0);
-    v = __adcIn;
-    printf("vin = %.4f\n", v);
-    puts("DONE.");
-}
-#else
-void post() {
-    puts("Checking serial communications with PuTTY");
-}
-#endif
--- a/post_may18.hpp	Mon Apr 30 14:07:05 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-#include "mbed.h"
-
-#ifndef __POST_MAY18__
-#define __POST_MAY18__
-
-// ****************** COMMENT OUT THIS LINE FOR YOUR OWN CODE *****************
-#define SOFT261_MAY18_HARDWARE_CHECK
-// ****************************************************************************
-
-extern void POST();
-
-#endif
\ No newline at end of file