Koos van der Wat
/
StandardTimer
Standard timer for air dryer.
main.cpp@3:15c6c399f69c, 2019-11-29 (annotated)
- Committer:
- koosvanderwat
- Date:
- Fri Nov 29 10:17:21 2019 +0000
- Revision:
- 3:15c6c399f69c
- Parent:
- 2:ad0b044d0a10
No changes.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
koosvanderwat | 3:15c6c399f69c | 1 | /* Program for Standard Timer */ |
koosvanderwat | 3:15c6c399f69c | 2 | #include "mbed.h" |
koosvanderwat | 3:15c6c399f69c | 3 | #include "Watchdog1.h" |
koosvanderwat | 3:15c6c399f69c | 4 | |
koosvanderwat | 3:15c6c399f69c | 5 | // Host PC Communication channels |
koosvanderwat | 3:15c6c399f69c | 6 | //Serial pc(SERIAL_TX, SERIAL_RX); // tx, rx |
koosvanderwat | 3:15c6c399f69c | 7 | Serial pc(USBTX, USBRX); |
koosvanderwat | 3:15c6c399f69c | 8 | |
koosvanderwat | 3:15c6c399f69c | 9 | int PT = 120; // Purge time in seconds |
koosvanderwat | 3:15c6c399f69c | 10 | int RT = 60; // Repressurisation time in seconds |
koosvanderwat | 3:15c6c399f69c | 11 | int USBC = 0; // USB Communication |
koosvanderwat | 3:15c6c399f69c | 12 | |
koosvanderwat | 3:15c6c399f69c | 13 | Watchdog wd; |
koosvanderwat | 3:15c6c399f69c | 14 | |
koosvanderwat | 3:15c6c399f69c | 15 | Ticker timeKeeping; |
koosvanderwat | 3:15c6c399f69c | 16 | |
koosvanderwat | 3:15c6c399f69c | 17 | DigitalOut my_RHMV(A2); //RHMV |
koosvanderwat | 3:15c6c399f69c | 18 | DigitalOut my_RV(A1); //RV |
koosvanderwat | 3:15c6c399f69c | 19 | DigitalOut my_RHPV(A0); //RHPV |
koosvanderwat | 3:15c6c399f69c | 20 | DigitalOut my_LHPV(A3); //LHPV |
koosvanderwat | 3:15c6c399f69c | 21 | DigitalOut my_led(LED1); //ONLED |
simon | 1:7418a52375a0 | 22 | |
koosvanderwat | 3:15c6c399f69c | 23 | DigitalOut my_RHPVLED(D6); //RHPVLED |
koosvanderwat | 3:15c6c399f69c | 24 | DigitalOut my_RHMVLED(D5); //RHMVLED |
koosvanderwat | 3:15c6c399f69c | 25 | DigitalOut my_RVLED(D4); //RVLED |
koosvanderwat | 3:15c6c399f69c | 26 | DigitalOut my_LHMVLED(D3); //RHMVLED |
koosvanderwat | 3:15c6c399f69c | 27 | DigitalOut my_LHPVLED(D2); //LHPVLED |
koosvanderwat | 3:15c6c399f69c | 28 | |
koosvanderwat | 3:15c6c399f69c | 29 | int secondscounter = 0; |
koosvanderwat | 3:15c6c399f69c | 30 | |
koosvanderwat | 3:15c6c399f69c | 31 | int LHCT = PT + RT; // LH cycle time |
koosvanderwat | 3:15c6c399f69c | 32 | int LHPT = PT + RT + PT; // LH purge time |
koosvanderwat | 3:15c6c399f69c | 33 | int CT = PT + RT + PT + RT; // Cycle Time |
koosvanderwat | 3:15c6c399f69c | 34 | |
koosvanderwat | 3:15c6c399f69c | 35 | int main() |
koosvanderwat | 3:15c6c399f69c | 36 | { |
koosvanderwat | 3:15c6c399f69c | 37 | my_RHMV = 0; |
koosvanderwat | 3:15c6c399f69c | 38 | my_RHPV = 1; |
koosvanderwat | 3:15c6c399f69c | 39 | my_LHPV = 0; |
koosvanderwat | 3:15c6c399f69c | 40 | my_RV = 0; |
koosvanderwat | 3:15c6c399f69c | 41 | |
koosvanderwat | 3:15c6c399f69c | 42 | wd.Configure(4.0); |
koosvanderwat | 3:15c6c399f69c | 43 | |
koosvanderwat | 3:15c6c399f69c | 44 | pc.printf("Dryer Start\r\n"); |
koosvanderwat | 3:15c6c399f69c | 45 | |
koosvanderwat | 3:15c6c399f69c | 46 | while(1) { |
koosvanderwat | 3:15c6c399f69c | 47 | |
koosvanderwat | 3:15c6c399f69c | 48 | wd.Service(); |
koosvanderwat | 3:15c6c399f69c | 49 | my_led = !my_led; |
koosvanderwat | 3:15c6c399f69c | 50 | secondscounter = secondscounter + 1; |
koosvanderwat | 3:15c6c399f69c | 51 | wait(1); |
koosvanderwat | 3:15c6c399f69c | 52 | |
koosvanderwat | 3:15c6c399f69c | 53 | if (USBC == 1) { |
simon | 0:334327d1a416 | 54 | |
koosvanderwat | 3:15c6c399f69c | 55 | if (secondscounter <= PT) { |
koosvanderwat | 3:15c6c399f69c | 56 | pc.printf("RH DRYING LH REGEN\r\n"); |
koosvanderwat | 3:15c6c399f69c | 57 | } |
koosvanderwat | 3:15c6c399f69c | 58 | if (secondscounter > PT && secondscounter <= LHCT) { |
koosvanderwat | 3:15c6c399f69c | 59 | pc.printf("RH DRYING LH REPRESS\r\n"); |
koosvanderwat | 3:15c6c399f69c | 60 | } |
koosvanderwat | 3:15c6c399f69c | 61 | if ((secondscounter > LHCT) && (secondscounter <= LHPT)) { |
koosvanderwat | 3:15c6c399f69c | 62 | pc.printf("LH DRYING RH REGEN\r\n"); |
koosvanderwat | 3:15c6c399f69c | 63 | } |
koosvanderwat | 3:15c6c399f69c | 64 | if (secondscounter > LHPT && (secondscounter <= CT)) { |
koosvanderwat | 3:15c6c399f69c | 65 | pc.printf("LH DRYING RH REPRESS\r\n"); |
koosvanderwat | 3:15c6c399f69c | 66 | } |
koosvanderwat | 3:15c6c399f69c | 67 | } // (USB == 1) |
koosvanderwat | 3:15c6c399f69c | 68 | |
koosvanderwat | 3:15c6c399f69c | 69 | if (secondscounter <= PT) { |
koosvanderwat | 3:15c6c399f69c | 70 | |
koosvanderwat | 3:15c6c399f69c | 71 | my_RHMV = 0; |
koosvanderwat | 3:15c6c399f69c | 72 | my_RHPV = 1; |
koosvanderwat | 3:15c6c399f69c | 73 | my_LHPV = 0; |
koosvanderwat | 3:15c6c399f69c | 74 | my_RV = 0; |
koosvanderwat | 3:15c6c399f69c | 75 | |
koosvanderwat | 3:15c6c399f69c | 76 | my_RHPVLED = 1; //RHPVLED |
koosvanderwat | 3:15c6c399f69c | 77 | my_RHMVLED = 0; //RHMVLED |
koosvanderwat | 3:15c6c399f69c | 78 | my_RVLED = 0; //RVLED |
koosvanderwat | 3:15c6c399f69c | 79 | my_LHMVLED = 1; //LHMVLED |
koosvanderwat | 3:15c6c399f69c | 80 | my_LHPVLED = 0; //LHPVLED |
koosvanderwat | 3:15c6c399f69c | 81 | } |
koosvanderwat | 3:15c6c399f69c | 82 | if (secondscounter > PT && secondscounter <= LHCT) { |
koosvanderwat | 3:15c6c399f69c | 83 | my_RHMV = 0; |
koosvanderwat | 3:15c6c399f69c | 84 | my_RHPV = 0; |
koosvanderwat | 3:15c6c399f69c | 85 | my_LHPV = 0; |
koosvanderwat | 3:15c6c399f69c | 86 | my_RV = 1; |
simon | 0:334327d1a416 | 87 | |
koosvanderwat | 3:15c6c399f69c | 88 | my_RHPVLED = 0; //RHPVLED |
koosvanderwat | 3:15c6c399f69c | 89 | my_RHMVLED = 0; //RHMVLED |
koosvanderwat | 3:15c6c399f69c | 90 | my_RVLED = 1; //RVLED |
koosvanderwat | 3:15c6c399f69c | 91 | my_LHMVLED = 1; //LHMVLED |
koosvanderwat | 3:15c6c399f69c | 92 | my_LHPVLED = 0; //LHPVLED |
koosvanderwat | 3:15c6c399f69c | 93 | } |
koosvanderwat | 3:15c6c399f69c | 94 | |
koosvanderwat | 3:15c6c399f69c | 95 | if ((secondscounter > LHCT) && (secondscounter <= LHPT)) { |
koosvanderwat | 3:15c6c399f69c | 96 | |
koosvanderwat | 3:15c6c399f69c | 97 | my_RHMV = 1; |
koosvanderwat | 3:15c6c399f69c | 98 | my_RHPV = 0; |
koosvanderwat | 3:15c6c399f69c | 99 | my_LHPV = 1; |
koosvanderwat | 3:15c6c399f69c | 100 | my_RV = 0; |
koosvanderwat | 3:15c6c399f69c | 101 | |
koosvanderwat | 3:15c6c399f69c | 102 | my_RHPVLED = 0; //RHPVLED |
koosvanderwat | 3:15c6c399f69c | 103 | my_RHMVLED = 1; //RHMVLED |
koosvanderwat | 3:15c6c399f69c | 104 | my_RVLED = 0; //RVLED |
koosvanderwat | 3:15c6c399f69c | 105 | my_LHMVLED = 0; //LHMVLED |
koosvanderwat | 3:15c6c399f69c | 106 | my_LHPVLED = 1; //LHPVLED |
koosvanderwat | 3:15c6c399f69c | 107 | } |
koosvanderwat | 3:15c6c399f69c | 108 | |
koosvanderwat | 3:15c6c399f69c | 109 | if (secondscounter > LHPT && (secondscounter <= CT)) { |
koosvanderwat | 3:15c6c399f69c | 110 | my_RHMV = 1; |
koosvanderwat | 3:15c6c399f69c | 111 | my_RHPV = 0; |
koosvanderwat | 3:15c6c399f69c | 112 | my_LHPV = 0; |
koosvanderwat | 3:15c6c399f69c | 113 | my_RV = 1; |
koosvanderwat | 3:15c6c399f69c | 114 | |
koosvanderwat | 3:15c6c399f69c | 115 | my_RHPVLED = 0; //RHPVLED |
koosvanderwat | 3:15c6c399f69c | 116 | my_RHMVLED = 1; //RHMVLED |
koosvanderwat | 3:15c6c399f69c | 117 | my_RVLED = 1; //RVLED |
koosvanderwat | 3:15c6c399f69c | 118 | my_LHMVLED = 0; //LHMVLED |
koosvanderwat | 3:15c6c399f69c | 119 | my_LHPVLED = 0; //LHPVLED |
koosvanderwat | 3:15c6c399f69c | 120 | } |
koosvanderwat | 3:15c6c399f69c | 121 | |
koosvanderwat | 3:15c6c399f69c | 122 | if (secondscounter == (CT)) { |
koosvanderwat | 3:15c6c399f69c | 123 | secondscounter = 0; |
koosvanderwat | 3:15c6c399f69c | 124 | } |
koosvanderwat | 3:15c6c399f69c | 125 | }//While |
koosvanderwat | 3:15c6c399f69c | 126 | }//main() |