A little code that uses strcmp to compare user input via USB serial
Dependencies: SevenSegLed USBDevice mbed
Diff: main.cpp
- Revision:
- 0:7b39f2056c89
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Oct 07 12:44:35 2014 +0000 @@ -0,0 +1,77 @@ +#include "mbed.h" +#include "USBSerial.h" +#include "SevenSegLed.h" + +//Virtual serial port over USB +USBSerial serial; +int countdown; +char userinput[9]; +int x =1; + +int main(void) { + + + while(1) + { + wait(3); + for(countdown = 3; countdown>=0; countdown--) + { + serial.printf("%d\r\n",countdown); + wait(1); + + } + + serial.printf("\nPlease enter your name...\r\n"); + + serial.scanf("%s", &userinput); + wait(1); + + + + if(strcmp("rantistic",userinput) == 0) + { + serial.printf("\n\rThank you, you have entered your name, the program will now return to countdown"); + for(int i =0; i<=3; i++) + { + wait(1); + if(i==3) + serial.printf(".\n"); + else + serial.printf("."); + } + + serial.printf("\n\r"); + + } + + else if(strcmp("milan", userinput) == 0) + { + serial.printf("\n\rMilan is a city...Go home! The program will now return to countdown"); + for(int i =0; i<=3; i++) + { + wait(1); + if(i==3) + serial.printf(".\n"); + else + serial.printf("."); + } + + serial.printf("\n\r"); + } + + else if(strcmp("susan", userinput) == 0) + { + serial.printf("\n\rSusan! What are you still doing here, workaholic...go home!\r\n"); + } + + + else + { + + 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"); + } + + + + } +} \ No newline at end of file