Simple program to poll all the adc channels on the KL25Z and print the values on PC terminal.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
echo88
Date:
Tue Dec 02 17:10:42 2014 +0000
Parent:
0:0dfe9e81dd93
Commit message:
Simple program to poll all the ADC channels on KL25Z

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 0dfe9e81dd93 -r 5e86133b210a main.cpp
--- a/main.cpp	Tue Sep 30 17:50:15 2014 +0000
+++ b/main.cpp	Tue Dec 02 17:10:42 2014 +0000
@@ -1,17 +1,46 @@
+/*************************************************************************************************
+frdm_simple_adc
+
+**************************************************************************************************/
 #include "mbed.h"
 
+/* Defines */
+#define READ_INTERVAL 0.1 //Seconds
+
+/* Objects */
 Serial pc(USBTX, USBRX);
 AnalogIn analog0(PTB0);
+AnalogIn analog1(PTB1);
+AnalogIn analog2(PTB2);
+AnalogIn analog3(PTB3);
+AnalogIn analog4(PTC2);
+AnalogIn analog5(PTC1);
 
-float adcRead0;
+/* Global Variales */
+float adcRead0, adcRead1, adcRead2, adcRead3, adcRead4, adcRead5;
 
+/* Function Prototypes */
+
+/* Main Routine */
 int main()
 {
-    pc.printf("Reading A/D Channels\n\r");
+    pc.printf("\nElapsed Time[ms], PTB0[V], PTB1[V], PTB2[V], PTB3[V], PTC2[V], PTC1[V]\n");
+    
     while(1)
-    {
-        adcRead0 = analog0;
-        wait(0.5);
-        pc.printf("%1.3f \n\r", adcRead0);
+    {     
+        /* Poll Analog Sensors */       
+        adcRead0 = analog0*3.3;
+        adcRead1 = analog1*3.3;
+        adcRead2 = analog2*3.3;
+        adcRead3 = analog3*3.3;
+        adcRead4 = analog4*3.3;
+        adcRead5 = analog5*3.3;
+        
+        /* Print ADC values to Terminal */
+        pc.printf("%1.3f, %1.3f, %1.3f, %1.3f, %1.3f, %1.3f\n\r", 
+                    adcRead0, adcRead1, adcRead2, adcRead3, adcRead4, adcRead5);
+        
+        /* Delay for set time interval and increment time counter */
+        wait(READ_INTERVAL);
     }
 }
\ No newline at end of file