Serial PC and Timer example

Dependencies:   mbed

Committer:
Kit1
Date:
Sun Sep 01 10:33:17 2013 +0000
Revision:
0:06ea14e458e3
Serial PC example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kit1 0:06ea14e458e3 1 /*Program 5: Reads input voltage through the ADC, and transfers to PC terminal */
Kit1 0:06ea14e458e3 2 #include "mbed.h"
Kit1 0:06ea14e458e3 3
Kit1 0:06ea14e458e3 4 Serial pc(USBTX, USBRX); //enable serial port which links to USB
Kit1 0:06ea14e458e3 5 AnalogIn Ain(p20);
Kit1 0:06ea14e458e3 6 Timer t;
Kit1 0:06ea14e458e3 7 float ADCdata;
Kit1 0:06ea14e458e3 8
Kit1 0:06ea14e458e3 9 int main() {
Kit1 0:06ea14e458e3 10 pc.printf("ADC Data Values…\n\r"); //send an opening text message
Kit1 0:06ea14e458e3 11 while(1){
Kit1 0:06ea14e458e3 12 t.start();
Kit1 0:06ea14e458e3 13 for (int i=0;i<=9;i++) {
Kit1 0:06ea14e458e3 14 ADCdata=ADCdata+Ain*3.3; //sum 10 samples
Kit1 0:06ea14e458e3 15 }
Kit1 0:06ea14e458e3 16 ADCdata=ADCdata/10; //divide by 10
Kit1 0:06ea14e458e3 17 wait(0.5);
Kit1 0:06ea14e458e3 18 pc.printf("%1.3f \n\r",ADCdata); //send the data to the terminal
Kit1 0:06ea14e458e3 19 t.stop();
Kit1 0:06ea14e458e3 20 printf("The time taken was %f seconds\n", t.read());
Kit1 0:06ea14e458e3 21 }
Kit1 0:06ea14e458e3 22 }