Logs analog data

Dependencies:   SDFileSystem mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //  ANALOG SENSORS
00002 //  Logs information from all 6 analog inputs for 5 seconds in 100msec intervals (this is adjustable)
00003 //  and writes the data to a "log.fbr" file on the SD card.
00004 
00005 #define INTERVAL 0.100         //100 msec interval
00006 #define NUM_OF_READINGS 50     //number of readings to be logged
00007 #define MAX_VOLTAGE 3.3        //Readings are normalised to values between 0 and 1, need to multiply readings by 3.3V
00008 #include "mbed.h"
00009 #include "SDFileSystem.h"
00010 #include <fstream>
00011 #include <iomanip>
00012 
00013 AnalogIn ain1(p15);   // SENSOR PINOUTS
00014 AnalogIn ain2(p16);
00015 AnalogIn ain3(p17);
00016 AnalogIn ain4(p18);
00017 AnalogIn ain5(p19);
00018 AnalogIn ain6(p20);
00019 
00020 DigitalOut led(LED1);   // LED PINOUT
00021 
00022 SDFileSystem sd(p5, p6, p7, p8, "sd");   //SD CARD PINOUT
00023 
00024 ofstream out;  // define output stream
00025 
00026 int main() {
00027 
00028     out.open("/sd/log.fbr");
00029     out<<"START LOGGING\n";
00030     
00031     for(int n=1;n<=NUM_OF_READINGS;n++)
00032     {
00033     out<<setw(2)<<n
00034     <<setw(10)<<ain1*MAX_VOLTAGE
00035     <<setw(10)<<ain2*MAX_VOLTAGE
00036     <<setw(10)<<ain3*MAX_VOLTAGE
00037     <<setw(10)<<ain4*MAX_VOLTAGE
00038     <<setw(10)<<ain5*MAX_VOLTAGE
00039     <<setw(10)<<ain6*MAX_VOLTAGE
00040     <<endl;
00041     
00042     wait(INTERVAL);
00043     }
00044   
00045     out<<"END LOGGING\n";
00046     out.close();  // close output stream
00047     
00048     //////////////////////////////////////////////////////////////////////////////////////////
00049     led=1;
00050     wait(0.5);
00051     led=0;        // After the LED blinks, the program is done and the SD card may be removed.
00052     //////////////////////////////////////////////////////////////////////////////////////////
00053 }