A serial parser for a specific project

Dependencies:   mbed

Fork of Serial_HelloWorld_Mbed by mbed official

main.cpp

Committer:
philipgoosen
Date:
2015-07-14
Revision:
6:da101b92bc2d
Parent:
5:1ba2b0e9e582
Child:
7:d25708589910

File content as of revision 6:da101b92bc2d:

#include "mbed.h"
// Data parser by Philip Goosen
 
 /*#define TX USBTX
 #define RX USBRX*/
 
#define TX PA_2
#define RX PA_3
 
Serial pc(TX, RX); // tx, rx
DigitalOut led(LED1);
 
 int isDigit(char digit)
{
    if (digit >= '0' or digit <= '9')
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

int isLetter(char let) // Only works for upper case
{
    if (let >= 'A' or let <= 'Z')
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

int isAlpha(char c)
{
    if( isDigit(c) or isLetter(c) )
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

int toDigit(char c)
{
    return (c - '0');
}

int main()
{
    int motor = 0;
    int direction = 0;
    int speed = 0;
    
    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
                
                    //int count = toDigit(c);
                    int x = 0;
                    
                    while (x < 3)
                    {
                        pc.printf("%d ", x);
                        x++;
                    }
                    //while loop with counter
        }
    }
}