Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of AnalogIn_HelloWorld by
Diff: main.cpp
- Revision:
- 3:5fc7b56ebe8c
- Parent:
- 0:101a12a915c6
--- 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(); + } }