simple program with serial communication

Dependencies:   mbed

Committer:
rockstar
Date:
Sun May 29 17:28:15 2016 +0000
Revision:
0:4373931b350e
NITH version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rockstar 0:4373931b350e 1 #include "mbed.h"
rockstar 0:4373931b350e 2
rockstar 0:4373931b350e 3 DigitalOut myled(LED2);
rockstar 0:4373931b350e 4 Serial xbee(PTE0,PTE1);
rockstar 0:4373931b350e 5 Serial pc(USBTX,USBRX);
rockstar 0:4373931b350e 6 int main() {
rockstar 0:4373931b350e 7 pc.printf("We are here");
rockstar 0:4373931b350e 8 xbee.baud(9600);
rockstar 0:4373931b350e 9 pc.baud(9600);
rockstar 0:4373931b350e 10 while(1) {
rockstar 0:4373931b350e 11 if(xbee.readable())
rockstar 0:4373931b350e 12 { int val= xbee.getc();
rockstar 0:4373931b350e 13 pc.putc(val);}
rockstar 0:4373931b350e 14 if(pc.readable())
rockstar 0:4373931b350e 15 {char val1= pc.getc();
rockstar 0:4373931b350e 16 xbee.putc(val1);}
rockstar 0:4373931b350e 17 myled = !myled;
rockstar 0:4373931b350e 18 wait(1);
rockstar 0:4373931b350e 19 }
rockstar 0:4373931b350e 20 }/*
rockstar 0:4373931b350e 21 Serial pc(USBTX, USBRX); //enable serial port which links to USB
rockstar 0:4373931b350e 22 AnalogIn Ain(p20);
rockstar 0:4373931b350e 23 Timer t;
rockstar 0:4373931b350e 24 float ADCdata;
rockstar 0:4373931b350e 25
rockstar 0:4373931b350e 26 int main() {
rockstar 0:4373931b350e 27 pc.printf("ADC Data Values…\n\r"); //send an opening text message
rockstar 0:4373931b350e 28 while(1){
rockstar 0:4373931b350e 29 t.start();
rockstar 0:4373931b350e 30 ADCdata=0;
rockstar 0:4373931b350e 31 for (int i=0;i<=9;i++) {
rockstar 0:4373931b350e 32 ADCdata=ADCdata + Ain; //sum 10 samples
rockstar 0:4373931b350e 33 }
rockstar 0:4373931b350e 34 ADCdata=(ADCdata/10)*3.3; //divide by 10
rockstar 0:4373931b350e 35 wait(0.5);
rockstar 0:4373931b350e 36 pc.printf("%1.3f \n\r",ADCdata); //send the data to the terminal
rockstar 0:4373931b350e 37 t.stop();
rockstar 0:4373931b350e 38 printf("The time taken was %f seconds\n", t.read());
rockstar 0:4373931b350e 39 }
rockstar 0:4373931b350e 40 }*/