Read analog value from MCP3201 serial ADC converter SPI interface.

Dependencies:   mbed

Revision:
0:f9b5c272f6ed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri May 06 18:50:55 2016 +0000
@@ -0,0 +1,27 @@
+/* 
+    Read analog channel from MCP3201 with SPI interface and send it to the serial interface.
+*/
+
+#include "mbed.h"
+#include "mcp3201.h"
+
+#define ADC_SCALE_VALUE 3.3/4096 
+
+Serial pc(USBTX, USBRX); // tx, rx
+ 
+int main() 
+{
+    pc.printf("Analog read test from MCP3201.\n");
+    
+    while(1) 
+    {    
+    float r=(float)ReadAnalogMCP3201() * ADC_SCALE_VALUE; // show value in volts.
+    pc.printf("AD channel value: %4.2f Volts.\r\n", r);
+    pc.printf(" Press any key to get new sample...\r\n\r\n");
+    char c = pc.getc();
+    }
+}
+
+
+    
+