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

Dependencies:   SevenSegLed USBDevice mbed

Committer:
rantistic
Date:
Tue Oct 07 12:44:35 2014 +0000
Revision:
0:7b39f2056c89
This is a little code that uses strcmp to compare user inputs via USB serial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rantistic 0:7b39f2056c89 1 #include "mbed.h"
rantistic 0:7b39f2056c89 2 #include "USBSerial.h"
rantistic 0:7b39f2056c89 3 #include "SevenSegLed.h"
rantistic 0:7b39f2056c89 4
rantistic 0:7b39f2056c89 5 //Virtual serial port over USB
rantistic 0:7b39f2056c89 6 USBSerial serial;
rantistic 0:7b39f2056c89 7 int countdown;
rantistic 0:7b39f2056c89 8 char userinput[9];
rantistic 0:7b39f2056c89 9 int x =1;
rantistic 0:7b39f2056c89 10
rantistic 0:7b39f2056c89 11 int main(void) {
rantistic 0:7b39f2056c89 12
rantistic 0:7b39f2056c89 13
rantistic 0:7b39f2056c89 14 while(1)
rantistic 0:7b39f2056c89 15 {
rantistic 0:7b39f2056c89 16 wait(3);
rantistic 0:7b39f2056c89 17 for(countdown = 3; countdown>=0; countdown--)
rantistic 0:7b39f2056c89 18 {
rantistic 0:7b39f2056c89 19 serial.printf("%d\r\n",countdown);
rantistic 0:7b39f2056c89 20 wait(1);
rantistic 0:7b39f2056c89 21
rantistic 0:7b39f2056c89 22 }
rantistic 0:7b39f2056c89 23
rantistic 0:7b39f2056c89 24 serial.printf("\nPlease enter your name...\r\n");
rantistic 0:7b39f2056c89 25
rantistic 0:7b39f2056c89 26 serial.scanf("%s", &userinput);
rantistic 0:7b39f2056c89 27 wait(1);
rantistic 0:7b39f2056c89 28
rantistic 0:7b39f2056c89 29
rantistic 0:7b39f2056c89 30
rantistic 0:7b39f2056c89 31 if(strcmp("rantistic",userinput) == 0)
rantistic 0:7b39f2056c89 32 {
rantistic 0:7b39f2056c89 33 serial.printf("\n\rThank you, you have entered your name, the program will now return to countdown");
rantistic 0:7b39f2056c89 34 for(int i =0; i<=3; i++)
rantistic 0:7b39f2056c89 35 {
rantistic 0:7b39f2056c89 36 wait(1);
rantistic 0:7b39f2056c89 37 if(i==3)
rantistic 0:7b39f2056c89 38 serial.printf(".\n");
rantistic 0:7b39f2056c89 39 else
rantistic 0:7b39f2056c89 40 serial.printf(".");
rantistic 0:7b39f2056c89 41 }
rantistic 0:7b39f2056c89 42
rantistic 0:7b39f2056c89 43 serial.printf("\n\r");
rantistic 0:7b39f2056c89 44
rantistic 0:7b39f2056c89 45 }
rantistic 0:7b39f2056c89 46
rantistic 0:7b39f2056c89 47 else if(strcmp("milan", userinput) == 0)
rantistic 0:7b39f2056c89 48 {
rantistic 0:7b39f2056c89 49 serial.printf("\n\rMilan is a city...Go home! The program will now return to countdown");
rantistic 0:7b39f2056c89 50 for(int i =0; i<=3; i++)
rantistic 0:7b39f2056c89 51 {
rantistic 0:7b39f2056c89 52 wait(1);
rantistic 0:7b39f2056c89 53 if(i==3)
rantistic 0:7b39f2056c89 54 serial.printf(".\n");
rantistic 0:7b39f2056c89 55 else
rantistic 0:7b39f2056c89 56 serial.printf(".");
rantistic 0:7b39f2056c89 57 }
rantistic 0:7b39f2056c89 58
rantistic 0:7b39f2056c89 59 serial.printf("\n\r");
rantistic 0:7b39f2056c89 60 }
rantistic 0:7b39f2056c89 61
rantistic 0:7b39f2056c89 62 else if(strcmp("susan", userinput) == 0)
rantistic 0:7b39f2056c89 63 {
rantistic 0:7b39f2056c89 64 serial.printf("\n\rSusan! What are you still doing here, workaholic...go home!\r\n");
rantistic 0:7b39f2056c89 65 }
rantistic 0:7b39f2056c89 66
rantistic 0:7b39f2056c89 67
rantistic 0:7b39f2056c89 68 else
rantistic 0:7b39f2056c89 69 {
rantistic 0:7b39f2056c89 70
rantistic 0:7b39f2056c89 71 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");
rantistic 0:7b39f2056c89 72 }
rantistic 0:7b39f2056c89 73
rantistic 0:7b39f2056c89 74
rantistic 0:7b39f2056c89 75
rantistic 0:7b39f2056c89 76 }
rantistic 0:7b39f2056c89 77 }