Koos van der Wat / Mbed 2 deprecated StandardTimer

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* Program for Standard Timer */
00002 #include "mbed.h"
00003 #include "Watchdog1.h"
00004 
00005 // Host PC Communication channels
00006 //Serial pc(SERIAL_TX, SERIAL_RX); // tx, rx
00007 Serial pc(USBTX, USBRX);
00008 
00009 int PT = 120; // Purge time in seconds
00010 int RT = 60; // Repressurisation time in seconds
00011 int USBC = 0; // USB Communication
00012 
00013 Watchdog wd;
00014 
00015 Ticker              timeKeeping;
00016 
00017 DigitalOut my_RHMV(A2); //RHMV
00018 DigitalOut my_RV(A1); //RV
00019 DigitalOut my_RHPV(A0); //RHPV
00020 DigitalOut my_LHPV(A3); //LHPV
00021 DigitalOut my_led(LED1);  //ONLED
00022 
00023 DigitalOut my_RHPVLED(D6); //RHPVLED
00024 DigitalOut my_RHMVLED(D5); //RHMVLED
00025 DigitalOut my_RVLED(D4); //RVLED
00026 DigitalOut my_LHMVLED(D3); //RHMVLED
00027 DigitalOut my_LHPVLED(D2); //LHPVLED
00028 
00029 int secondscounter = 0;
00030 
00031 int LHCT = PT + RT; // LH cycle time
00032 int LHPT = PT + RT + PT; // LH purge time
00033 int CT = PT + RT + PT + RT; // Cycle Time
00034 
00035 int main()
00036 {
00037     my_RHMV = 0;
00038     my_RHPV = 1;
00039     my_LHPV = 0;
00040     my_RV = 0;
00041 
00042     wd.Configure(4.0);
00043 
00044     pc.printf("Dryer Start\r\n");
00045 
00046     while(1) {
00047 
00048         wd.Service();
00049         my_led = !my_led;
00050         secondscounter = secondscounter + 1;
00051         wait(1);
00052 
00053         if (USBC == 1) {
00054 
00055             if (secondscounter <= PT) {
00056                 pc.printf("RH DRYING LH REGEN\r\n");
00057             }
00058             if (secondscounter > PT && secondscounter <= LHCT) {
00059                 pc.printf("RH DRYING LH REPRESS\r\n");
00060             }
00061             if ((secondscounter > LHCT) && (secondscounter <= LHPT)) {
00062                 pc.printf("LH DRYING RH REGEN\r\n");
00063             }
00064             if (secondscounter > LHPT && (secondscounter <= CT)) {
00065                 pc.printf("LH DRYING RH REPRESS\r\n");
00066             }
00067         } // (USB == 1)
00068 
00069         if (secondscounter <= PT) {
00070 
00071             my_RHMV = 0;
00072             my_RHPV = 1;
00073             my_LHPV = 0;
00074             my_RV = 0;
00075 
00076             my_RHPVLED = 1;  //RHPVLED
00077             my_RHMVLED = 0;  //RHMVLED
00078             my_RVLED = 0;  //RVLED
00079             my_LHMVLED = 1;  //LHMVLED
00080             my_LHPVLED = 0;  //LHPVLED
00081         }
00082         if (secondscounter > PT && secondscounter <= LHCT) {
00083             my_RHMV = 0;
00084             my_RHPV = 0;
00085             my_LHPV = 0;
00086             my_RV = 1;
00087 
00088             my_RHPVLED = 0;  //RHPVLED
00089             my_RHMVLED = 0;  //RHMVLED
00090             my_RVLED = 1;  //RVLED
00091             my_LHMVLED = 1;  //LHMVLED
00092             my_LHPVLED = 0;  //LHPVLED
00093         }
00094 
00095         if ((secondscounter > LHCT) && (secondscounter <= LHPT)) {
00096 
00097             my_RHMV = 1;
00098             my_RHPV = 0;
00099             my_LHPV = 1;
00100             my_RV = 0;
00101 
00102             my_RHPVLED = 0;  //RHPVLED
00103             my_RHMVLED = 1;  //RHMVLED
00104             my_RVLED = 0;  //RVLED
00105             my_LHMVLED = 0;  //LHMVLED
00106             my_LHPVLED = 1;  //LHPVLED
00107         }
00108 
00109         if (secondscounter > LHPT && (secondscounter <= CT)) {
00110             my_RHMV = 1;
00111             my_RHPV = 0;
00112             my_LHPV = 0;
00113             my_RV = 1;
00114 
00115             my_RHPVLED = 0;  //RHPVLED
00116             my_RHMVLED = 1;  //RHMVLED
00117             my_RVLED = 1;  //RVLED
00118             my_LHMVLED = 0;  //LHMVLED
00119             my_LHPVLED = 0;  //LHPVLED
00120         }
00121 
00122         if (secondscounter == (CT)) {
00123             secondscounter = 0;
00124         }
00125     }//While
00126 }//main()