SOFT261 2018 May Coursework Power On Self Test application

Committer:
noutram
Date:
Tue May 01 11:21:13 2018 +0000
Revision:
4:3d7da70d57a1
Parent:
3:6eb00bb6e76a
Child:
5:b3323f02b914
Fixes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
noutram 0:aed251004373 1 #include "mbed.h"
noutram 2:c8dc7c4c7bda 2 //
noutram 2:c8dc7c4c7bda 3 // Coursework Template 1.0
noutram 2:c8dc7c4c7bda 4 //
noutram 3:6eb00bb6e76a 5 // Please clone and edit as appropriate. Please read comments below.
noutram 3:6eb00bb6e76a 6 //
noutram 3:6eb00bb6e76a 7 //
noutram 3:6eb00bb6e76a 8 // Function declarations
noutram 3:6eb00bb6e76a 9 void POST();
noutram 0:aed251004373 10
noutram 3:6eb00bb6e76a 11 //*****************************************************************************
noutram 3:6eb00bb6e76a 12 // 1. COMMENT OUT THIS LINE FOR YOUR OWN CODE
noutram 3:6eb00bb6e76a 13 #define SOFT261_MAY18_HARDWARE_CHECK
noutram 3:6eb00bb6e76a 14 // ****************************************************************************
noutram 1:ba08c1d4da51 15
noutram 3:6eb00bb6e76a 16 #ifdef SOFT261_MAY18_HARDWARE_CHECK
noutram 3:6eb00bb6e76a 17 //Hardware declarations for the full power-on self test.
noutram 3:6eb00bb6e76a 18 DigitalOut redLed(D7);
noutram 3:6eb00bb6e76a 19 DigitalOut yellowLed(D6);
noutram 3:6eb00bb6e76a 20 DigitalOut greenLed(D5);
noutram 3:6eb00bb6e76a 21 DigitalIn sw1(D4);
noutram 3:6eb00bb6e76a 22 DigitalIn sw2(D3);
noutram 3:6eb00bb6e76a 23 AnalogIn adcIn(A0);
noutram 3:6eb00bb6e76a 24 int main() { POST(); while (true); }
noutram 3:6eb00bb6e76a 25 #else
noutram 3:6eb00bb6e76a 26 // ****************************************************************************
noutram 3:6eb00bb6e76a 27 // 2. Declare your driver objects here - some are done for you
noutram 3:6eb00bb6e76a 28 // ****************************************************************************
noutram 0:aed251004373 29 DigitalOut redLed(D7);
noutram 0:aed251004373 30 DigitalOut yellowLed(D6);
noutram 0:aed251004373 31 DigitalOut greenLed(D5);
noutram 0:aed251004373 32 AnalogIn adcIn(A0);
noutram 0:aed251004373 33
noutram 0:aed251004373 34
noutram 3:6eb00bb6e76a 35 // ****************************************************************************
noutram 3:6eb00bb6e76a 36 // 3. Write task code here
noutram 3:6eb00bb6e76a 37 // ****************************************************************************
noutram 3:6eb00bb6e76a 38
noutram 3:6eb00bb6e76a 39 //Main function - your entry point and often main loop
noutram 0:aed251004373 40 int main()
noutram 0:aed251004373 41 {
noutram 3:6eb00bb6e76a 42 POST(); //Power on self test - you can leave this here if you wish
noutram 3:6eb00bb6e76a 43
noutram 3:6eb00bb6e76a 44 //Infinite loop (you may remove if you wish)
noutram 3:6eb00bb6e76a 45 while (true) {
noutram 3:6eb00bb6e76a 46
noutram 3:6eb00bb6e76a 47 }
noutram 0:aed251004373 48 }
noutram 3:6eb00bb6e76a 49 #endif
noutram 0:aed251004373 50
noutram 3:6eb00bb6e76a 51
noutram 3:6eb00bb6e76a 52
noutram 3:6eb00bb6e76a 53
noutram 3:6eb00bb6e76a 54
noutram 3:6eb00bb6e76a 55
noutram 3:6eb00bb6e76a 56
noutram 3:6eb00bb6e76a 57
noutram 3:6eb00bb6e76a 58 // ***************************************************************************
noutram 3:6eb00bb6e76a 59 // No changes beyond this point
noutram 3:6eb00bb6e76a 60 // ***************************************************************************
noutram 3:6eb00bb6e76a 61
noutram 3:6eb00bb6e76a 62 //
noutram 3:6eb00bb6e76a 63 // POWER ON SELF TEST (POST)
noutram 3:6eb00bb6e76a 64 #ifdef SOFT261_MAY18_HARDWARE_CHECK
noutram 3:6eb00bb6e76a 65 void POST() {
noutram 3:6eb00bb6e76a 66 //Check serial interface is configured
noutram 3:6eb00bb6e76a 67 puts("Checking serial communications with PuTTY");
noutram 3:6eb00bb6e76a 68
noutram 3:6eb00bb6e76a 69 //Check switches
noutram 3:6eb00bb6e76a 70 puts("Press switches now");
noutram 3:6eb00bb6e76a 71 wait(1.0);
noutram 4:3d7da70d57a1 72 int s1 = sw1;
noutram 4:3d7da70d57a1 73 int s2 = sw2;
noutram 3:6eb00bb6e76a 74 printf("Switch 1 state = %s\n", (s1 == 1) ? "PRESSED" : "RELEASED");
noutram 3:6eb00bb6e76a 75 printf("Switch 2 state = %s\n", (s2 == 1) ? "PRESSED" : "RELEASED");
noutram 3:6eb00bb6e76a 76 puts("Release the switches");
noutram 3:6eb00bb6e76a 77 wait(1.0);
noutram 4:3d7da70d57a1 78 s1 = sw1;
noutram 4:3d7da70d57a1 79 s2 = sw2;
noutram 3:6eb00bb6e76a 80 printf("Switch 1 state = %s\n", (s1 == 1) ? "PRESSED" : "RELEASED");
noutram 3:6eb00bb6e76a 81 printf("Switch 2 state = %s\n", (s2 == 1) ? "PRESSED" : "RELEASED");
noutram 3:6eb00bb6e76a 82
noutram 3:6eb00bb6e76a 83 //Check LEDs
noutram 3:6eb00bb6e76a 84 puts("Checking LEDs");
noutram 3:6eb00bb6e76a 85 for (unsigned int n=0; n<5; n++) {
noutram 3:6eb00bb6e76a 86 puts("red");
noutram 4:3d7da70d57a1 87 redLed = 1;
noutram 4:3d7da70d57a1 88 yellowLed = 0;
noutram 4:3d7da70d57a1 89 greenLed = 0;
noutram 3:6eb00bb6e76a 90 wait(0.2);
noutram 3:6eb00bb6e76a 91 puts("yellow");
noutram 4:3d7da70d57a1 92 redLed = 0;
noutram 4:3d7da70d57a1 93 yellowLed = 1;
noutram 4:3d7da70d57a1 94 greenLed = 0;
noutram 3:6eb00bb6e76a 95 wait(0.2);
noutram 3:6eb00bb6e76a 96 puts("green");
noutram 4:3d7da70d57a1 97 redLed = 0;
noutram 4:3d7da70d57a1 98 yellowLed = 0;
noutram 4:3d7da70d57a1 99 greenLed = 1;
noutram 3:6eb00bb6e76a 100 wait(0.2);
noutram 3:6eb00bb6e76a 101 }
noutram 3:6eb00bb6e76a 102 //Check switches
noutram 4:3d7da70d57a1 103 greenLed = 0;
noutram 3:6eb00bb6e76a 104
noutram 3:6eb00bb6e76a 105 //Finally the ADC
noutram 3:6eb00bb6e76a 106 puts("Check ADC - turn potentiometer");
noutram 3:6eb00bb6e76a 107 wait(1.0);
noutram 4:3d7da70d57a1 108 float v = adcIn;
noutram 3:6eb00bb6e76a 109 printf("vin = %.4f\n", v);
noutram 3:6eb00bb6e76a 110 puts("Check ADC - turn potentiometer again");
noutram 3:6eb00bb6e76a 111 wait(1.0);
noutram 4:3d7da70d57a1 112 v = adcIn;
noutram 3:6eb00bb6e76a 113 printf("vin = %.4f\n", v);
noutram 3:6eb00bb6e76a 114 puts("DONE.");
noutram 3:6eb00bb6e76a 115 }
noutram 3:6eb00bb6e76a 116 #else
noutram 3:6eb00bb6e76a 117 void POST() {
noutram 3:6eb00bb6e76a 118 puts("Checking serial communications with PuTTY");
noutram 3:6eb00bb6e76a 119 }
noutram 3:6eb00bb6e76a 120 #endif