Analog measurements at A0 (PA_5) with averaging

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 AnalogIn ain(A0);                           // Analog input at PA0
00004 uint32_t mysum;                             // Used for summation
00005 
00006 int main()
00007 {
00008     printf("\r\n Lab03_analog_thermometer - with averaging\r\n");
00009     while(1) {
00010         mysum = 0;
00011         for(int i=0; i<3300; i++) {
00012             mysum += ain.read_u16();        // sum up raw 16-bit data
00013         }
00014         float voltage = mysum>>16;       // voltage in millivolts
00015         float tempC = (voltage - 500)/10; // tempereature in Celsius
00016         printf(" voltage: %5.0f mV temp: %5.1f °C\r\n",voltage,tempC);
00017         wait(2);
00018     }
00019 }