A serial parser for a specific project
Fork of Serial_HelloWorld_Mbed by
main.cpp
- Committer:
- philipgoosen
- Date:
- 2015-07-14
- Revision:
- 4:178b04ae427e
- Parent:
- 3:3399899d714b
- Child:
- 5:1ba2b0e9e582
File content as of revision 4:178b04ae427e:
#include "mbed.h" /*#define TX USBTX #define RX USBRX*/ #define TX PA_2 #define RX PA_3 Serial pc(TX, RX); // tx, rx DigitalOut led(LED1); int checkDigit(char digit) { if (digit >= '0' or digit <= '9') { return 1; } else { return 0; } } int toDigit(char c) { return (c - '0'); } int main() { led=1; wait(0.5); led=0; pc.baud(115200); pc.printf("Philip's program"); while(1) { //pc.putc(pc.getc() + 1); if (pc.getc() == '$' && pc.getc() == '#') { /*led=1; wait(1); led=0; led=1; wait(1); led=0;*/ char c = pc.getc();// Gets a character from the computer that should be a digit from 0 - 9 if (checkDigit(c)) { int count = toDigit(c); int x = 0; while (x < count) { pc.printf("%d ", x); x++; } //while loop with counter } } } }