A code to drive a 3sensor reading unit for monitoring the operation opf a closed circuit rebreather (CCR) with 3 electrogalvanic sensors. Also uses a DS1307 for realtime clock and an MPX5700 to read the depth (mounted inside the breathing loop to keep it 'dry'). circuit diagrams available on rebreather world.

Dependencies:   DS1307 TextOLED mbed

Rebmon_main.cpp

Committer:
pegcjs
Date:
2012-08-01
Revision:
0:52d05d950581
Child:
1:9cff4feccbce

File content as of revision 0:52d05d950581:

//lpc1124lcddemo
#include "ds1307.h"
#include "mbed.h"
#include "TextLCD.h"

//pin assignments and declarations
// LCD display
TextLCD g_lcd(p26, p25, p24, p23, p22, p21);  // RS, E, DB4, DB5, DB6, DB7

//onboard leds
DigitalOut led1(LED1);
DigitalOut led2(LED2);

// warning leds
DigitalOut red(p34);
DigitalOut green(p33);
DigitalOut blue(p30);

// switches and buttons
DigitalIn CAL(p36);
DigitalIn SW1(p35);

// log data storage
LocalFileSystem local("local");

// adc inputs for sensors
AnalogIn depin(p20);
AnalogIn EG1(p19);
AnalogIn EG2(p18);
AnalogIn Vbatt(p17);

// realtime clock
DS1307 my1307(p28,p27); // start DS1307 class and give it pins for connections of the DS1307 device

// variables for realtime clock
int sec = 0;
int min = 0;
int hours = 0;
int day = 0;
int date = 0;
int month = 0;
int year = 0;


int main() {
    // get time to log a startup time
    my1307.gettime( &sec, &min, &hours, &day, &date, &month, &year);
    int starttime=year*365*24*60*60+month*30*24*60*60+day*24*60*60+hours*60*60+min*60+sec; //simple timestamp = # seconds since midnight jan 1st 2000 if all months were 30 days.
    

    int seconds;
    float depth;

// setup local file to store data in
    FILE *fp = fopen("/local/out.txt", "a");  // Open "out.txt" on the local file system for writing




g_lcd.cls();

g_lcd.locate(0, 0);
g_lcd.printf( "Hello world!");

while (1) {
    g_lcd.locate(0, 1);
    my1307.gettime( &sec, &min, &hours, &day, &date, &month, &year);
    seconds=day*24*60*60+hours*60*60+min*60+sec; // seconds since the start of this month....

    if (led1==0) led1=1;
    else led1=0;
    g_lcd.printf( "%.2d:%.2d:%.2d", hours,min,sec);

    iCounter++;
    depth=depin/0.020;
    if (iCounter <=60) {
        fprintf(fp, "%d\t%e\n",seconds,depth);
        g_lcd.locate(0,0);
        g_lcd.printf("Writing data  ");
    } else {
        g_lcd.locate(0,0);
        g_lcd.printf("Closed file  ");
    }
    if (iCounter==61) {
        fclose(fp);
    }
    g_lcd.locate(9,1);
    g_lcd.printf("%3.1f",depth);
    wait(1.0);
}
}