Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of serial_communication by
main.cpp
- Committer:
- Andy8800
- Date:
- 2016-02-21
- Revision:
- 0:15ca75f6e1a0
- Child:
- 1:32c006ad8eaf
File content as of revision 0:15ca75f6e1a0:
#include "mbed.h"
#include <string>
DigitalOut myled(LED1);
Serial pc(USBTX, USBRX);
//***********************************************************************************
//***Set up the Serial communication to your PC**************************************
//***Type some Keys and when pressing enter, mbed will send some analyzed strings****
//***********************************************************************************
int main()
{
char ch[40];
int count=0;
char buf1[30];
char buf2[30];
while(1)
{
if(pc.readable())
{
//store char in char array (ch)
ch[count]= pc.getc();
//print out to PC for better visibility/response
pc.putc(ch[count]);
//if receiving ENTER - print out everything and reset counter
if(ch[count] == '\r')
{
pc.printf("\n\rCharacters received: %d \n\r",count);
pc.printf("First three characters: %c%c%c \n\r",ch[0],ch[1],ch[2]);
pc.printf("Second three characters: %c%c%c \n\r",ch[3],ch[4],ch[5]);
//devide ch array into two separate char arrays
sprintf(buf1,"%c%c%c",ch[0],ch[1],ch[2]);
sprintf(buf2,"%c%c%c",ch[3],ch[4],ch[5]);
//***compare the two new char arrays***************************************************
if(strcmp(buf1,buf2) == 0)
{
pc.printf("First and second three characters are identicaly: %s \n\n\r",buf1);
}
else
{
pc.printf("First and second three characters are not identicaly \n\n\r");
}
//****************************************************************************************
count=0;
}
//else count up and store all received char's in the array
else
{
count++;
}
}
}
}
