Finalized Code for Assignment 1: Lucy Damon

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 
00004 //Lucy Damon Assignment 1
00005 
00006 //The purpose of this assignment is to utilize a for loop to activate different cases.
00007 
00008 
00009 
00010 
00011 
00012 
00013 Serial pc(USBTX, USBRX);
00014 
00015 
00016 DigitalOut myled(LED1);
00017 
00018 int main()
00019 {
00020 
00021     float a;
00022 
00023     for (int n=1; n<6; n++) {      //==> [(i=1) initialization] [(i++)= i+1)] [i<6 = loop condition/stop condition] as long as i is less than 6, it will execute this for loop.
00024         a = (float) n;
00025 
00026 
00027 
00028         switch (n) {
00029             case 1:
00030                 pc.printf("a=%f ; minimum\r\n",a);//code to be executed if n=1
00031                 wait(2);
00032 
00033                 break;
00034             case 2:
00035                 pc.printf("a=%f ; low\r\n",a);//code to be executed if n=2
00036 
00037                 wait(2);
00038 
00039                 break;
00040 
00041 
00042             case 3:
00043                 pc.printf("a=%f ; medium\r\n",a);//code to be executed if n=2
00044                 wait(2);
00045 
00046                 break;
00047             case 4:
00048                 pc.printf("a=%f ; high\r\n",a);//code to be executed if n=2
00049                 wait(2);
00050 
00051                 break;
00052             case 5:
00053                 pc.printf("a=%f ; maximum\r\n",a);//code to be executed if n=2
00054                 wait(2);
00055 
00056                 break;
00057             default:
00058                 pc.printf("you failed the assignment\r\n");//code to be executed if n doesnt match above statements
00059 
00060         }
00061 
00062 
00063 
00064 
00065 
00066 
00067     }
00068 
00069 
00070 
00071 }
00072 
00073 
00074 
00075 
00076