Testing Analog from LDR
Dependencies: mbed
Fork of PE_05-04_LoggingData by
main.cpp@1:a8d819e5c10d, 2014-11-18 (annotated)
- Committer:
- Richard37
- Date:
- Tue Nov 18 12:40:35 2014 +0000
- Revision:
- 1:a8d819e5c10d
- Parent:
- 0:ec4e2bc1996f
This looks at various AD input formats
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
robt | 0:ec4e2bc1996f | 1 | /*Program Example 5.4: Reads input voltage through the ADC, and transfers to PC terminal |
robt | 0:ec4e2bc1996f | 2 | */ |
robt | 0:ec4e2bc1996f | 3 | #include "mbed.h" |
robt | 0:ec4e2bc1996f | 4 | Serial pc(USBTX, USBRX); //enable serial port which links to USB |
Richard37 | 1:a8d819e5c10d | 5 | AnalogIn Ain(A0); |
robt | 0:ec4e2bc1996f | 6 | |
Richard37 | 1:a8d819e5c10d | 7 | unsigned int ADCdata; |
Richard37 | 1:a8d819e5c10d | 8 | float LightVolts; |
robt | 0:ec4e2bc1996f | 9 | int main() { |
robt | 0:ec4e2bc1996f | 10 | pc.printf("ADC Data Values...\n\r"); //send an opening text message |
robt | 0:ec4e2bc1996f | 11 | while(1){ |
Richard37 | 1:a8d819e5c10d | 12 | ADCdata=Ain.read_u16(); |
Richard37 | 1:a8d819e5c10d | 13 | //LightVolts=ADCdata*3.3; |
robt | 0:ec4e2bc1996f | 14 | wait(0.5); |
Richard37 | 1:a8d819e5c10d | 15 | // pc.printf("%1.3f \n\r",LightVolts); //send the data to the terminal |
Richard37 | 1:a8d819e5c10d | 16 | pc.printf("%x \n\r",ADCdata); //send the data to the terminal |
robt | 0:ec4e2bc1996f | 17 | } |
robt | 0:ec4e2bc1996f | 18 | } |
robt | 0:ec4e2bc1996f | 19 |