A little code that uses strcmp to compare user input via USB serial

Dependencies:   SevenSegLed USBDevice mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "USBSerial.h"
00003 #include "SevenSegLed.h"
00004  
00005 //Virtual serial port over USB
00006 USBSerial serial;
00007 int countdown;
00008 char userinput[9];
00009 int x =1;
00010 
00011 int main(void) {
00012 
00013 
00014     while(1)
00015     {
00016         wait(3);
00017         for(countdown = 3; countdown>=0; countdown--)
00018         {
00019             serial.printf("%d\r\n",countdown);
00020             wait(1);
00021             
00022         }
00023         
00024             serial.printf("\nPlease enter your name...\r\n");
00025 
00026             serial.scanf("%s", &userinput);
00027             wait(1);
00028     
00029       
00030         
00031         if(strcmp("rantistic",userinput) == 0)
00032         {
00033             serial.printf("\n\rThank you, you have entered your name, the program will now return to countdown");
00034             for(int i =0; i<=3; i++)
00035             {
00036                 wait(1);
00037                 if(i==3)
00038                 serial.printf(".\n");
00039                 else
00040                 serial.printf(".");
00041             }
00042             
00043             serial.printf("\n\r");
00044   
00045         }
00046         
00047         else if(strcmp("milan", userinput) == 0)
00048         {
00049             serial.printf("\n\rMilan is a city...Go home! The program will now return to countdown");
00050             for(int i =0; i<=3; i++)
00051             {
00052                 wait(1);
00053                 if(i==3)
00054                 serial.printf(".\n");
00055                 else
00056                 serial.printf(".");
00057             }
00058             
00059             serial.printf("\n\r");
00060         }
00061         
00062         else if(strcmp("susan", userinput) == 0)
00063         {
00064             serial.printf("\n\rSusan! What are you still doing here, workaholic...go home!\r\n");
00065         }
00066         
00067         
00068         else
00069         {
00070            
00071             serial.printf("ERROR, INCORRECT...ur PC is about to crash! Save all work NOW or a massive virus will wipe it all out!\r\n");
00072         }
00073         
00074     
00075         
00076     }
00077 }