Lab 2 - Exercise 1 Analog to Digital Conversion using a variable potentiometer

Dependencies:   mbed

Committer:
brianconnett
Date:
Thu Aug 14 15:43:31 2014 +0000
Revision:
1:7e6087973b59
Parent:
0:1171c72f5f28
ES305 Lab2 - Exercise 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
brianconnett 1:7e6087973b59 1 //****************************************
brianconnett 1:7e6087973b59 2 // ES305 Linear Control Systems
brianconnett 1:7e6087973b59 3 // Lab 2 - Introduction to mbed microcontroller
brianconnett 1:7e6087973b59 4 // Exercise 1 - Analog to Digital Conversion
brianconnett 1:7e6087973b59 5 // Reads variable input through the ADC, and transfers to PC terminal
brianconnett 1:7e6087973b59 6 //
brianconnett 1:7e6087973b59 7 // Brian Connett, LCDR, USN
brianconnett 1:7e6087973b59 8 //****************************************
brianconnett 1:7e6087973b59 9
brianconnett 1:7e6087973b59 10 #include "mbed.h" //mbed header file from mbed.org includes MOST APIs required to operate LPC
brianconnett 1:7e6087973b59 11
brianconnett 1:7e6087973b59 12 Serial pc(USBTX, USBRX); //Create a Serial port connected to USB
brianconnett 1:7e6087973b59 13 AnalogIn Ain(p18); //Create an AnalogIn variable connected to Pin 18
brianconnett 1:7e6087973b59 14 float ADCdata; //Variable declaration to store Analog values
brianconnett 1:7e6087973b59 15
brianconnett 1:7e6087973b59 16 int main()
brianconnett 1:7e6087973b59 17 {
brianconnett 1:7e6087973b59 18 pc.baud(921600); //Set baud rate on Serial port to 921600
brianconnett 1:7e6087973b59 19 pc.printf("ADC Data Values... \n\r");
brianconnett 1:7e6087973b59 20 while (1) {
brianconnett 1:7e6087973b59 21 ADCdata=Ain; //Store AnalogIn value from Pin 18 into float variable
brianconnett 1:7e6087973b59 22 pc.printf("Analog Value: %f Voltage Value: %f \n\r",ADCdata,ADCdata*3.3); //Print to TeraTerm via Serial TX
brianconnett 1:7e6087973b59 23 wait (01.0); //Delay for Analysis
brianconnett 1:7e6087973b59 24 }
brianconnett 1:7e6087973b59 25 }