part1

Dependencies:   mbed

Committer:
jaredwil
Date:
Tue Feb 10 20:37:52 2015 +0000
Revision:
0:2c98a4766d9f
Child:
1:93eb2c653c86
part1;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jaredwil 0:2c98a4766d9f 1 #include "mbed.h"
jaredwil 0:2c98a4766d9f 2 #include "string.h"
jaredwil 0:2c98a4766d9f 3 #include <string>
jaredwil 0:2c98a4766d9f 4
jaredwil 0:2c98a4766d9f 5 //Initialize PWM
jaredwil 0:2c98a4766d9f 6 PwmOut PWM1(p21);
jaredwil 0:2c98a4766d9f 7 Serial pc(USBTX, USBRX);
jaredwil 0:2c98a4766d9f 8
jaredwil 0:2c98a4766d9f 9 //Initialize variables that will be used to read
jaredwil 0:2c98a4766d9f 10 std::string input;
jaredwil 0:2c98a4766d9f 11
jaredwil 0:2c98a4766d9f 12
jaredwil 0:2c98a4766d9f 13 int main()
jaredwil 0:2c98a4766d9f 14 {
jaredwil 0:2c98a4766d9f 15 while(1){
jaredwil 0:2c98a4766d9f 16 if(pc.readable()) {
jaredwil 0:2c98a4766d9f 17 char c = pc.getc();
jaredwil 0:2c98a4766d9f 18 x = strlen(input);
jaredwil 0:2c98a4766d9f 19 //If enter is pressed process input
jaredwil 0:2c98a4766d9f 20 if(c == '\r'){
jaredwil 0:2c98a4766d9f 21 //check to see if valid input
jaredwil 0:2c98a4766d9f 22 if(sizeof(input) == 7){
jaredwil 0:2c98a4766d9f 23 pc.printf("%s",input); //print input for debugging
jaredwil 0:2c98a4766d9f 24 input.clear(); //clear input
jaredwil 0:2c98a4766d9f 25 }
jaredwil 0:2c98a4766d9f 26 //mark as invalid input clear data
jaredwil 0:2c98a4766d9f 27 else{
jaredwil 0:2c98a4766d9f 28 input.clear(); //clear input
jaredwil 0:2c98a4766d9f 29 pc.printf("Invalid Input /n"); //print space
jaredwil 0:2c98a4766d9f 30 }
jaredwil 0:2c98a4766d9f 31 }
jaredwil 0:2c98a4766d9f 32 //Else add the character to current input
jaredwil 0:2c98a4766d9f 33 else{
jaredwil 0:2c98a4766d9f 34 // add character to current input string
jaredwil 0:2c98a4766d9f 35 input = input + c;
jaredwil 0:2c98a4766d9f 36 pc.printf("%s\n",input); //print input for debugging
jaredwil 0:2c98a4766d9f 37 pc.printf("%d",sizeof(input));
jaredwil 0:2c98a4766d9f 38 }
jaredwil 0:2c98a4766d9f 39 wait(0.1);
jaredwil 0:2c98a4766d9f 40 }
jaredwil 0:2c98a4766d9f 41
jaredwil 0:2c98a4766d9f 42
jaredwil 0:2c98a4766d9f 43
jaredwil 0:2c98a4766d9f 44 }
jaredwil 0:2c98a4766d9f 45 }
jaredwil 0:2c98a4766d9f 46