Michael Steel
/
mbed_plant_rig_chem_dose
chemical dosing section of the rig
Fork of mbed_plant_rig by
Revision 1:d022bdae586b, committed 2017-07-29
- Comitter:
- Demonthorn
- Date:
- Sat Jul 29 15:49:12 2017 +0000
- Parent:
- 0:790a9e0285d6
- Commit message:
- dosing rig
Changed in this revision
DHT11.lib | Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 790a9e0285d6 -r d022bdae586b DHT11.lib --- a/DHT11.lib Mon Jul 10 15:23:02 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://developer.mbed.org/users/Demonthorn/code/DHT11/#65c4ca53154d
diff -r 790a9e0285d6 -r d022bdae586b main.cpp --- a/main.cpp Mon Jul 10 15:23:02 2017 +0000 +++ b/main.cpp Sat Jul 29 15:49:12 2017 +0000 @@ -1,41 +1,48 @@ //////////////////////////////////////////////////////////////// -// Plant Research Rig V1.1.05 // +// Plant dosing Rig V1.0.06 // // Michael Steel // //////////////////////////////////////////////////////////////// // Libraries #include "mbed.h" -#include "Dht11.h" #include "ConfigFile.h" // Define I/O and constants Serial pc(USBTX, USBRX); -Dht11 sensor(p5); -DigitalIn LOG_SWITCH(p20); -DigitalOut TEMP_BLED(p7); -DigitalOut TEMP_GLED(p8); -DigitalOut TEMP_RLED(p9); -DigitalOut FAN(p10); -DigitalOut HEAT(p11); +DigitalOut DOSE_PUMP(p5); +DigitalOut BLED(p7); +DigitalOut GLED(p8); +DigitalOut RLED(p9); +Timeout dosing; LocalFileSystem local("local"); ConfigFile cfg; -float TEMP; -float TEMPHH; -float TEMPH; -float TEMPL; -float TEMPLL; +float DOSEI; +float DOSED; +float LOG_INDEX; /*while not necesary with a single test subject +this will allow for the proper selection of output message in the full version*/ int TCHECK; int YEAR; +char buffer[21]; +void DOSE(void) +{ + DOSE_PUMP = 1; + GLED = 1; + time_t seconds = time(NULL); + strftime(buffer, 21,"%X, %x\n", localtime(&seconds)); + wait (DOSED); + DOSE_PUMP = 0; + GLED = 0; + LOG_INDEX = 1; +} int main() { + // Determins Input file variables - char *key1 = "TEMPHH"; - char *key2 = "TEMPH"; - char *key3 = "TEMPL"; - char *key4 = "TEMPLL"; + char *key1 = "DOSEI"; + char *key2 = "DOSED"; char *key5 = "YEAR"; char value[BUFSIZ]; @@ -48,7 +55,6 @@ // Check correct time and get the current time from the terminal if needed struct tm t; time_t seconds = time(NULL); - char buffer[21]; strftime(buffer, 21, "%Y\n", localtime(&seconds)); TCHECK = atoi(buffer) ; if (TCHECK != YEAR ) { @@ -66,76 +72,43 @@ // display the time time_t seconds = time(NULL); + } - //printf("\r\n Time as a basic string = %s \r\n", ctime(&seconds)); wait(1); if (cfg.getValue(key1, &value[0], sizeof(value))) { pc.printf("'%s'='%s'\r\n", key1, value); - TEMPHH = atof(value) ; + DOSEI = atof(value) ; } else { pc.printf("Failure to get a configuration. Please check config file"); } if (cfg.getValue(key2, &value[0], sizeof(value))) { pc.printf("'%s'='%s'\r\n", key2, value); - TEMPH = atof(value) ; + DOSED = atof(value) ; } - if (cfg.getValue(key3, &value[0], sizeof(value))) { - pc.printf("'%s'='%s'\r\n", key3, value); - TEMPL = atof(value) ; - } - if (cfg.getValue(key4, &value[0], sizeof(value))) { - pc.printf("'%s'='%s'\r\n", key4, value); - TEMPLL = atof(value) ; - } + Ticker dosing; + dosing.attach(&DOSE, DOSEI); // setup dosing to call DOSE after DOSEI "dose interval" seconds + pc.printf("Begin logging \r\n"); while(1) { - while(LOG_SWITCH == 1) { - - sensor.read() ; - time_t seconds = time(NULL); - strftime(buffer, 21,"%X, %x\n", localtime(&seconds)); - FILE *fp = fopen("/local/out.txt", "a"); // Open "out.txt" on the local file system for writing - fprintf(fp, "\r\n T: %f, H: %f, %s,",sensor.getCelsius(),sensor.getHumidity(),buffer); - fclose(fp); - - pc.printf("\r\n T: %f, H: %f, %s,",sensor.getCelsius(),sensor.getHumidity(),buffer); - TEMP = sensor.getCelsius(); - if (TEMP >= TEMPHH) { - FAN = 1; - HEAT = 0; - TEMP_RLED = 1; - TEMP_GLED = 0; - TEMP_BLED = 0; - pc.printf(" Temperature in High Alarm"); - } else if (TEMP >= TEMPH) { - FAN = 1; - HEAT = 0; - TEMP_RLED = 0; - TEMP_GLED = 1; - TEMP_BLED = 0; - } else if (TEMP >= TEMPL) { - FAN = 0; - HEAT = 0; - TEMP_RLED = 0; - TEMP_GLED = 1; - TEMP_BLED = 0; - } else if (TEMP >= TEMPLL) { - FAN = 0; - HEAT = 1; - TEMP_RLED = 0; - TEMP_GLED = 1; - TEMP_BLED = 0; - } else { - FAN = 0; - HEAT = 1; - TEMP_RLED = 0; - TEMP_GLED = 0; - TEMP_BLED = 1; - pc.printf(" Temperature in Low Alarm"); - } - wait(1); + if (LOG_INDEX == 1) { + FILE *fp = fopen("/local/out.txt", "a"); // Open "out.txt" on the local file system for writing + fprintf(fp, "\r\n %f s dose given at %s",DOSED ,buffer); + fclose(fp); + pc.printf("\r\n %f s dose given to test subject 1 at %s",DOSED ,buffer); + LOG_INDEX = 0; + } + /*if (LOG_INDEX == 2){ + FILE *fp = fopen("/local/out.txt", "a"); // Open "out.txt" on the local file system for writing + fprintf(fp, "\r\n T: %f s dose given at %s,",DOSEI,buffer); + fclose(fp); + pc.printf("\r\n T: %f s dose given to test subject 2 at %s,",DOSEI,buffer); + LOG_INDEX = 0; + } + // this is then repeated for each test subject with sequential numbers */ - } + wait(1); + + } }