Read an analog value using ADC.

Dependencies:   mbed

Revision:
3:7cef8e5abfe5
Parent:
1:0490a15c76e4
diff -r 6d058686efbf -r 7cef8e5abfe5 main.cpp
--- a/main.cpp	Thu Mar 12 08:22:00 2015 +0000
+++ b/main.cpp	Sun Sep 04 08:04:35 2016 +0000
@@ -1,24 +1,28 @@
+/****************************************************************************
+ ****** 3-axis Accelerometer ADXL335 or GY-61 interfacing to FRDM-KL25Z *****
+ ******                  Author :  SHIVAM TRIPATHI                     ******  
+ ***************************************************************************/
+
 #include "mbed.h"
- 
-AnalogIn analog_value(A0);
- 
+
+Serial pc(USBTX, USBRX);
+AnalogIn analog_value1(A0);  //Output of X-axis at analog pin A0  ........ (Refer pinout)
+AnalogIn analog_value2(A1);  //Output of y-axis at analog pin A1
+AnalogIn analog_value3(A2);  //Output of z-axis at analog pin A1
+
 DigitalOut led(LED1);
 
 int main() {
-    float meas;
+    int x,y,z;
     
     printf("\nAnalogIn example\n");
     
     while(1) {
-        meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
-        meas = meas * 3300; // Change the value to be in the 0 to 3300 range
-        printf("measure = %.0f mV\n", meas);
-        if (meas > 2000) { // If the value is greater than 2V then switch the LED on
-          led = 1;
-        }
-        else {
-          led = 0;
-        }
-        wait(0.2); // 200 ms
+        x = analog_value1.read_u16();           // Reads X-axis value and then converts in 16 bit format (3.3V --> 65535).........Analog values are read
+        y = analog_value2.read_u16();           // Reads Y-axis value and then converts in 16 bit format (3.3V --> 65535)
+        z = analog_value3.read_u16();           // Reads Z-axis value and then converts in 16 bit format (3.3V --> 65535)
+        printf("\r x = %d  y = %d  z = %d  \n", x,y,z);    //Prints output on pc Serial terminal (serial USB com driver is a must)
+        wait(0.5); // 500 ms
+        
     }
 }