Protegemed / Mbed 2 deprecated mcp3201

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* 
00002     Read analog channel from MCP3201 with SPI interface and send it to the serial interface.
00003 */
00004 
00005 #include "mbed.h"
00006 #include "mcp3201.h"
00007 
00008 #define ADC_SCALE_VALUE 3.3/4096 
00009 
00010 Serial pc(USBTX, USBRX); // tx, rx
00011  
00012 int main() 
00013 {
00014     pc.printf("Analog read test from MCP3201.\n");
00015     
00016     while(1) 
00017     {    
00018     float r=(float)ReadAnalogMCP3201() * ADC_SCALE_VALUE; // show value in volts.
00019     pc.printf("AD channel value: %4.2f Volts.\r\n", r);
00020     pc.printf(" Press any key to get new sample...\r\n\r\n");
00021     char c = pc.getc();
00022     }
00023 }
00024 
00025 
00026     
00027