![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
ES305 Lab2 Exercise2 Analog to Digital Conversion using digital bus out to LED
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:7313e1b1dde1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Aug 14 15:45:16 2014 +0000 @@ -0,0 +1,37 @@ +//**************************************** +// ES305 Linear Control Systems +// Lab 2 - Introduction to mbed microcontroller +// Exercise 2 - Analog to Digital Conversion +// Reads variable input through the ADC, and control LED illumination using BusOut binary +// +// Brian Connett, LCDR, USN +//**************************************** + +#include "mbed.h" //mbed header file from mbed.org includes MOST APIs required to operate LPC + +Serial pc(USBTX, USBRX); //Create a Serial port connected to USB +AnalogIn Ain(p18); //Create an AnalogIn variable connected to Pin 18 +BusOut myLEDs(LED1,LED2,LED3,LED4); //Create a digital bus out, used for setting the state of collection of pins(LED) +float ADCdata; + +int main() +{ + pc.baud(921600); //Set up serial port baud rate + pc.printf("ADC Data Values... \n\r"); + while (1) { + ADCdata=Ain; + pc.printf("Analog Value: %f Voltage Value: %f \n\r",ADCdata,ADCdata*3.3); //Print to TeraTerm via Serial TX + wait (01.0); + if (ADCdata >= 0.8) //Conditional analysis that illuminates cooresponding LED + myLEDs=1; //when specific AnalogIn values are met + if (ADCdata < 0.8 && ADCdata >0.6) + myLEDs=3; + if (ADCdata < 0.6 && ADCdata >0.4) + myLEDs=7; + if (ADCdata < 0.4 && ADCdata >0.2) + myLEDs=15; + if (ADCdata < 0.2) + myLEDs=0; + + } +} \ No newline at end of file