Brian Wigfield
/
FoamTestbed
Foam device testing
Fork of AnalogIn_HelloWorld by
Revision 3:5fc7b56ebe8c, committed 2017-05-10
- Comitter:
- wspec
- Date:
- Wed May 10 05:13:19 2017 +0000
- Parent:
- 2:77750f8cba47
- Commit message:
- Sample rate
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Jan 19 10:16:20 2017 -0600 +++ b/main.cpp Wed May 10 05:13:19 2017 +0000 @@ -16,25 +16,25 @@ #include "mbed.h" -// Initialize a pins to perform analog input and digital output fucntions +// Initialize a pins to perform analog input and digital output functions AnalogIn ain(A0); -DigitalOut dout(LED1); +//DigitalOut dout(LED1); int main(void) { - while (1) { - // test the voltage on the initialized analog pin - // and if greater than 0.3 * VCC set the digital pin - // to a logic 1 otherwise a logic 0 - if(ain > 0.3f) { - dout = 1; - } else { - dout = 0; + Timer t; + int sampleCount = 0; + while(true) + { + t.start(); + while (sampleCount < 1000) { + float r = ain.read(); + sampleCount++; + //printf("Raw ADC Val: %f\n", ain.read()); + //printf("Voltage Val : %f\n",(ain.read_u16()&0xFFF)*3.3/4095); } - - // print the percentage and 16 bit normalized values - printf("percentage: %3.3f%%\n", ain.read()*100.0f); - printf("normalized: 0x%04X \n", ain.read_u16()); - wait(0.2f); - } + printf("Sample Count: %d in %fs\n",sampleCount, t.read()); + sampleCount = 0; + t.reset(); + } }