phil dani / Mbed 2 deprecated SerialPC

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*Program 5: Reads input voltage through the ADC, and transfers to PC terminal */
00002 #include "mbed.h"
00003 
00004 Serial pc(USBTX, USBRX); //enable serial port which links to USB
00005 AnalogIn Ain(p20);
00006 Timer t;
00007 float ADCdata;
00008 
00009 int main() {
00010     pc.printf("ADC Data Values…\n\r"); //send an opening text message 
00011     while(1){
00012         t.start();
00013          for (int i=0;i<=9;i++) {
00014             ADCdata=ADCdata+Ain*3.3; //sum 10 samples
00015         }
00016         ADCdata=ADCdata/10; //divide by 10
00017         wait(0.5);
00018         pc.printf("%1.3f \n\r",ADCdata); //send the data to the terminal
00019         t.stop();
00020         printf("The time taken was %f seconds\n", t.read());
00021     }
00022 }