Simple training demonstration to show the use enumeration

Dependencies:   USBDevice mbed

Fork of ConstantsVariablesArrays by Jon Fuge

Files at this revision

API Documentation at this revision

Comitter:
jf1452
Date:
Tue Nov 26 09:52:16 2013 +0000
Parent:
3:0f80147842c2
Commit message:
Enumeration Example

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 0f80147842c2 -r c4e451a1890f main.cpp
--- a/main.cpp	Tue Nov 26 08:42:02 2013 +0000
+++ b/main.cpp	Tue Nov 26 09:52:16 2013 +0000
@@ -1,5 +1,5 @@
 /*******************************************************************************
-* This program demonstrates the use of constants, variables and arrays         *
+* This program demonstrates the use of enumeration                             *
 *                                                                              *
 * Jon Fuge                                                                     *
 * V1.0 25/11/2013 First issue of code                                          *
@@ -8,23 +8,16 @@
 #include "mbed.h"
 #include "USBSerial.h"
 
+enum DaysOfTheWeek { SUN , MON, TUE, WED, THUR, FRI, SAT };
+enum MonthsOfTheYear { JAN = 1, FEB, MAR, APR, MAY, JUN,\
+                       JUL, AUG, SEP, OCT, NOV, DEC};
+
 USBSerial serial; // Virtual serial port over USB. Use Teraterm as the interface
 
-const float fPI = 3.1415927; // Declare a value for PI
-const char cDIAMETER[4] = {15,18,14,17}; // constant array of circle diameters
-
-char cMatrix[2][3] = {{2,3,5},{7,11,13}}; // matrix array of circle diameters
 int main() {
-   float fCircumference; // Declare local variables
    wait (10); // Wait 10 seconds to connect port
 
-   // Calculate circumference then send the result to the USB serial port.
-   fCircumference = fPI * 16; // Magic numbers should be avoided!
-   serial.printf("Diameter:%i Circumference:%f\n\r", 16, fCircumference);
-   fCircumference = fPI * (float)cDIAMETER[2]; // accessing an array.
-   serial.printf("Diameter:%i Circumference:%f\n\r", cDIAMETER[2], fCircumference);
-   fCircumference = fPI * (float)cMatrix[0][1]; // accessing an array.
-   serial.printf("Diameter:%i Circumference:%f\n\r", cMatrix[0][1], fCircumference);
+   serial.printf("Sunday is day %i, April is the %i month of the year\n\r", SUN, APR);
 
    for(;;) {} // Loop forever
 }
\ No newline at end of file