Charles Tritt / Mbed 2 deprecated AtoDSpeed

Dependencies:   mbed

Fork of aReadConditional by Charles Tritt

Revision:
5:4dd07248d20e
Parent:
4:acc6be2bbe21
--- a/main.cpp	Fri Sep 22 19:51:46 2017 +0000
+++ b/main.cpp	Fri Sep 29 15:29:35 2017 +0000
@@ -1,39 +1,48 @@
 /*
-    Project: aReadConditional (for analog read conditional)
+    Project: AtoDSpeed
     File: main.cpp
-    
-    Reads from analog input, streams ASCII text to std serial using printf and
-    lights onboard LED. Also demonstrates use of floating point literal suffix
-    toeliminate warning and int constants for HIGH and LOW.
-    
+
+    Determines and diplays speed of A to D conversion. See notebook
+    documentation.
+
     Written by: Dr. C. S. Tritt
-    Created: 3/27/17 (v. 1.1)
-    
+    Created: 9/24/17 (v. 1.0)
+
 */
 #include "mbed.h"
 
-const int HIGH = 1; // Optional, but makes code more readable.
-const int LOW = 0; // Optional, but makes code more readable.
- 
-AnalogIn analog_value(A0); // Construct AnalogIn object called analog_value.
- 
-DigitalOut led(LED1); // Construct DigitalOut object called led.
+Serial pc(USBTX, NC, 9600); // Serial transmit only @ 9600 baud.
+Timer myTimer; // Timer to time read times.
+AnalogIn vSource(A0); // Construct AnalogIn object called analog_value.
+
+int main()
+{
+    printf("\nA to D Speed Test (v. 1.0)\n"); // Identify program.
 
-int main() {
-    float value; // Value to be read and sent to serial port.
+    const int SIZE = 20; // Number of array elements.
+    int viReading[SIZE]; // Integer array for readings.
+    float vfReading[SIZE]; // Float array for readings.
     
-    printf("\nAnalogIn example\n"); // Identify program.
+    myTimer.reset(); myTimer.start(); // Reset & start the time.
+    for (int i = 0; i <= SIZE - 1; i++) {
+        viReading[i] = vSource.read_u16();
+    }
+    printf("It took %i uS to read...\n", myTimer.read_us());
     
-    while(true) {
-        value = analog_value.read(); // Read the analog input value (0 to 1)
-        printf("Value = %f\n", value); // Send value as text via serial port.
-        if (value > 0.5f) { // Activate built-in LED. The f is optional.
-          led.write(HIGH);
-        }
-        else {
-          led.write(LOW);
-        }
-        printf("LED = %d\n", (int) led.read()); // Send LED state via serial. 
-        wait(0.5); // Half a second (500 mS).
+    myTimer.reset(); myTimer.start(); // Reset & start the time.    
+    for (int i = 0; i <= SIZE - 1; i++) {
+        printf("V[%i] = %i counts\n", i, viReading[i]);
     }
-}
\ No newline at end of file
+    printf("It took %i uS to send the results.\n", myTimer.read_us());
+    
+    myTimer.reset(); myTimer.start(); // Reset & start the time.
+    for (int i = 0; i <= SIZE - 1; i++) {
+        vfReading[i] = vSource.read();
+    }
+    printf("It took %i uS to read...\n", myTimer.read_us());
+    
+    myTimer.reset(); myTimer.start(); // Reset & start the time.    
+    for (int i = 0; i <= SIZE - 1; i++) {
+        printf("V[%i] = %f counts\n", i, vfReading[i]);
+    }
+    printf("It took %i uS to send the results.\n", myTimer.read_us());} 
\ No newline at end of file