Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of UnionExample by
Revision 4:c4e451a1890f, committed 2013-11-26
- Comitter:
- jf1452
- Date:
- Tue Nov 26 09:52:16 2013 +0000
- Parent:
- 3:0f80147842c2
- Child:
- 5:eb5c6ae5938b
- Commit message:
- Enumeration Example
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- 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
