![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
First draft to the functional spec
Dependencies: mbed Grove_LCD_RGB_Backlight DebounceIn
main.cpp@1:ca7bf48a2f71, 2019-10-08 (annotated)
- Committer:
- dattranvnfrr
- Date:
- Tue Oct 08 16:24:32 2019 +0000
- Revision:
- 1:ca7bf48a2f71
- Parent:
- 0:2f5d939d4a4a
- Child:
- 2:829038a1352b
fan on when door open
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dattranvnfrr | 0:2f5d939d4a4a | 1 | #include "Grove_LCD_RGB_Backlight.h" |
dattranvnfrr | 0:2f5d939d4a4a | 2 | #include "mbed.h" |
dattranvnfrr | 0:2f5d939d4a4a | 3 | #include "DebounceIn.h" |
dattranvnfrr | 1:ca7bf48a2f71 | 4 | |
dattranvnfrr | 1:ca7bf48a2f71 | 5 | |
dattranvnfrr | 1:ca7bf48a2f71 | 6 | #define OUT_OFF (0) |
dattranvnfrr | 1:ca7bf48a2f71 | 7 | #define OUT_ON (1) |
dattranvnfrr | 1:ca7bf48a2f71 | 8 | |
dattranvnfrr | 1:ca7bf48a2f71 | 9 | #define IN_OFF (1) |
dattranvnfrr | 1:ca7bf48a2f71 | 10 | #define IN_ON (0) |
dattranvnfrr | 1:ca7bf48a2f71 | 11 | |
dattranvnfrr | 1:ca7bf48a2f71 | 12 | |
dattranvnfrr | 0:2f5d939d4a4a | 13 | //input |
dattranvnfrr | 1:ca7bf48a2f71 | 14 | DebounceIn doorClosed(p5); //Check door status |
dattranvnfrr | 0:2f5d939d4a4a | 15 | DebounceIn cycleStartBtt(p14); //cycle start button |
dattranvnfrr | 1:ca7bf48a2f71 | 16 | DebounceIn stopBtt(p15); //stop button |
dattranvnfrr | 1:ca7bf48a2f71 | 17 | //InterruptIn stopBtt(p15); //stop button |
dattranvnfrr | 0:2f5d939d4a4a | 18 | //DigitalIn pot(p20); |
dattranvnfrr | 1:ca7bf48a2f71 | 19 | |
dattranvnfrr | 0:2f5d939d4a4a | 20 | //output |
dattranvnfrr | 0:2f5d939d4a4a | 21 | DigitalOut doorInterlock(p6); //Door interlock |
dattranvnfrr | 0:2f5d939d4a4a | 22 | DigitalOut fanRelay(p7); //Fan control |
dattranvnfrr | 0:2f5d939d4a4a | 23 | DigitalOut redRelay(p8); //Red light |
dattranvnfrr | 0:2f5d939d4a4a | 24 | DigitalOut yellowRelay(p11); //Yellow light |
dattranvnfrr | 0:2f5d939d4a4a | 25 | DigitalOut greenRelay(p12); //Green light |
dattranvnfrr | 0:2f5d939d4a4a | 26 | DigitalOut damperRelay(p13); //Damper solenoid control |
dattranvnfrr | 0:2f5d939d4a4a | 27 | DigitalOut damperRelayAlt(p16); //Damper solenoid toggle control |
dattranvnfrr | 0:2f5d939d4a4a | 28 | DigitalOut vfd(p17); //VFD Start relay |
dattranvnfrr | 1:ca7bf48a2f71 | 29 | |
dattranvnfrr | 0:2f5d939d4a4a | 30 | Grove_LCD_RGB_Backlight rgbLCD(p9, p10); //Timer display |
dattranvnfrr | 1:ca7bf48a2f71 | 31 | |
dattranvnfrr | 1:ca7bf48a2f71 | 32 | bool cancelPending = false; |
dattranvnfrr | 1:ca7bf48a2f71 | 33 | bool damperIsOpen; |
dattranvnfrr | 1:ca7bf48a2f71 | 34 | bool simulateMode = false; |
dattranvnfrr | 1:ca7bf48a2f71 | 35 | |
dattranvnfrr | 0:2f5d939d4a4a | 36 | I2C i2c(p9, p10); |
dattranvnfrr | 0:2f5d939d4a4a | 37 | //Serial pc(USBTX, USBRX); |
dattranvnfrr | 1:ca7bf48a2f71 | 38 | |
dattranvnfrr | 1:ca7bf48a2f71 | 39 | |
dattranvnfrr | 0:2f5d939d4a4a | 40 | //extern "C" void mbed_reset(); |
dattranvnfrr | 1:ca7bf48a2f71 | 41 | |
dattranvnfrr | 1:ca7bf48a2f71 | 42 | // Function declarations |
dattranvnfrr | 1:ca7bf48a2f71 | 43 | void damperRotate(int damper); |
dattranvnfrr | 1:ca7bf48a2f71 | 44 | void fullLineItoA(int m, char* str); |
dattranvnfrr | 1:ca7bf48a2f71 | 45 | void countDown(int s); //countdown in sec |
dattranvnfrr | 1:ca7bf48a2f71 | 46 | void fullStop(); |
dattranvnfrr | 1:ca7bf48a2f71 | 47 | void debugMode(); |
dattranvnfrr | 1:ca7bf48a2f71 | 48 | |
dattranvnfrr | 1:ca7bf48a2f71 | 49 | |
dattranvnfrr | 1:ca7bf48a2f71 | 50 | |
dattranvnfrr | 1:ca7bf48a2f71 | 51 | int main() |
dattranvnfrr | 1:ca7bf48a2f71 | 52 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 53 | //on power up status |
dattranvnfrr | 1:ca7bf48a2f71 | 54 | cycleStartBtt.mode(PullUp); |
dattranvnfrr | 1:ca7bf48a2f71 | 55 | cycleStartBtt.set_debounce_us(1000); |
dattranvnfrr | 1:ca7bf48a2f71 | 56 | cycleStartBtt.set_samples(100); |
dattranvnfrr | 1:ca7bf48a2f71 | 57 | wait(.1); |
dattranvnfrr | 1:ca7bf48a2f71 | 58 | |
dattranvnfrr | 1:ca7bf48a2f71 | 59 | doorClosed.mode(PullUp); |
dattranvnfrr | 1:ca7bf48a2f71 | 60 | doorClosed.set_debounce_us(1000); |
dattranvnfrr | 1:ca7bf48a2f71 | 61 | doorClosed.set_samples(100); |
dattranvnfrr | 1:ca7bf48a2f71 | 62 | wait(.1); |
dattranvnfrr | 1:ca7bf48a2f71 | 63 | |
dattranvnfrr | 1:ca7bf48a2f71 | 64 | stopBtt.mode(PullUp); |
dattranvnfrr | 1:ca7bf48a2f71 | 65 | stopBtt.set_debounce_us(1000); |
dattranvnfrr | 1:ca7bf48a2f71 | 66 | stopBtt.set_samples(100); |
dattranvnfrr | 1:ca7bf48a2f71 | 67 | wait(.5); |
dattranvnfrr | 1:ca7bf48a2f71 | 68 | |
dattranvnfrr | 1:ca7bf48a2f71 | 69 | rgbLCD.clear(); |
dattranvnfrr | 1:ca7bf48a2f71 | 70 | rgbLCD.setRGB(0x00, 0x66, 0xaa); //set the color |
dattranvnfrr | 1:ca7bf48a2f71 | 71 | rgbLCD.locate(0,0); |
dattranvnfrr | 1:ca7bf48a2f71 | 72 | |
dattranvnfrr | 1:ca7bf48a2f71 | 73 | if(cycleStartBtt == IN_ON && stopBtt == IN_ON) |
dattranvnfrr | 0:2f5d939d4a4a | 74 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 75 | simulateMode = true; |
dattranvnfrr | 1:ca7bf48a2f71 | 76 | rgbLCD.print("Simulating.... "); |
dattranvnfrr | 0:2f5d939d4a4a | 77 | wait(5); |
dattranvnfrr | 0:2f5d939d4a4a | 78 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 79 | if(stopBtt == IN_ON) |
dattranvnfrr | 0:2f5d939d4a4a | 80 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 81 | debugMode(); |
dattranvnfrr | 1:ca7bf48a2f71 | 82 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 83 | |
dattranvnfrr | 1:ca7bf48a2f71 | 84 | //Display startup countdown |
dattranvnfrr | 1:ca7bf48a2f71 | 85 | //Startin up and prep the tank |
dattranvnfrr | 0:2f5d939d4a4a | 86 | rgbLCD.clear(); |
dattranvnfrr | 0:2f5d939d4a4a | 87 | rgbLCD.locate(0,0); |
dattranvnfrr | 1:ca7bf48a2f71 | 88 | rgbLCD.print("Starting up... "); |
dattranvnfrr | 0:2f5d939d4a4a | 89 | |
dattranvnfrr | 1:ca7bf48a2f71 | 90 | vfd = OUT_OFF; |
dattranvnfrr | 1:ca7bf48a2f71 | 91 | damperIsOpen = false; // Assert and run the opener once |
dattranvnfrr | 1:ca7bf48a2f71 | 92 | damperRotate(1); //vent opened; |
dattranvnfrr | 1:ca7bf48a2f71 | 93 | if(!simulateMode) |
dattranvnfrr | 1:ca7bf48a2f71 | 94 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 95 | //doorInterlock = OUT_ON; |
dattranvnfrr | 1:ca7bf48a2f71 | 96 | fanRelay = OUT_ON; |
dattranvnfrr | 1:ca7bf48a2f71 | 97 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 98 | greenRelay = OUT_OFF; |
dattranvnfrr | 1:ca7bf48a2f71 | 99 | yellowRelay = OUT_OFF; |
dattranvnfrr | 1:ca7bf48a2f71 | 100 | redRelay = OUT_OFF; |
dattranvnfrr | 1:ca7bf48a2f71 | 101 | |
dattranvnfrr | 1:ca7bf48a2f71 | 102 | //start timer for 90sec |
dattranvnfrr | 1:ca7bf48a2f71 | 103 | countDown(90); |
dattranvnfrr | 1:ca7bf48a2f71 | 104 | |
dattranvnfrr | 1:ca7bf48a2f71 | 105 | /* |
dattranvnfrr | 1:ca7bf48a2f71 | 106 | //check for closed door before running fan |
dattranvnfrr | 1:ca7bf48a2f71 | 107 | while(doorClosed!=IN_ON) |
dattranvnfrr | 1:ca7bf48a2f71 | 108 | { |
dattranvnfrr | 0:2f5d939d4a4a | 109 | rgbLCD.clear(); |
dattranvnfrr | 0:2f5d939d4a4a | 110 | rgbLCD.locate(0,0); |
dattranvnfrr | 1:ca7bf48a2f71 | 111 | rgbLCD.print("Door is opened "); |
dattranvnfrr | 1:ca7bf48a2f71 | 112 | wait(.25); |
dattranvnfrr | 1:ca7bf48a2f71 | 113 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 114 | */ |
dattranvnfrr | 0:2f5d939d4a4a | 115 | |
dattranvnfrr | 1:ca7bf48a2f71 | 116 | //Tank is ready |
dattranvnfrr | 1:ca7bf48a2f71 | 117 | rgbLCD.locate(0,0); |
dattranvnfrr | 1:ca7bf48a2f71 | 118 | rgbLCD.print("Tank is ready! "); |
dattranvnfrr | 1:ca7bf48a2f71 | 119 | greenRelay = OUT_ON; //green light on |
dattranvnfrr | 1:ca7bf48a2f71 | 120 | doorInterlock = OUT_OFF; //interlock unlatched, ready to load material into the tank |
dattranvnfrr | 1:ca7bf48a2f71 | 121 | fanRelay = OUT_OFF; //fan off |
dattranvnfrr | 0:2f5d939d4a4a | 122 | |
dattranvnfrr | 1:ca7bf48a2f71 | 123 | cancelPending = false; |
dattranvnfrr | 0:2f5d939d4a4a | 124 | |
dattranvnfrr | 1:ca7bf48a2f71 | 125 | while(1) |
dattranvnfrr | 1:ca7bf48a2f71 | 126 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 127 | if(cancelPending) |
dattranvnfrr | 0:2f5d939d4a4a | 128 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 129 | cancelPending = false; |
dattranvnfrr | 1:ca7bf48a2f71 | 130 | |
dattranvnfrr | 1:ca7bf48a2f71 | 131 | //Display status |
dattranvnfrr | 1:ca7bf48a2f71 | 132 | greenRelay = OUT_OFF; //green light OFF |
dattranvnfrr | 1:ca7bf48a2f71 | 133 | yellowRelay = OUT_OFF; //yellow light OFF |
dattranvnfrr | 1:ca7bf48a2f71 | 134 | redRelay = OUT_ON; //turn red light ON |
dattranvnfrr | 1:ca7bf48a2f71 | 135 | rgbLCD.clear(); |
dattranvnfrr | 1:ca7bf48a2f71 | 136 | rgbLCD.locate(0,0); |
dattranvnfrr | 1:ca7bf48a2f71 | 137 | rgbLCD.print("CYCLE STOPPED. "); |
dattranvnfrr | 1:ca7bf48a2f71 | 138 | vfd = OUT_OFF; //pump off |
dattranvnfrr | 1:ca7bf48a2f71 | 139 | if(doorClosed == IN_ON && !simulateMode) |
dattranvnfrr | 1:ca7bf48a2f71 | 140 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 141 | doorInterlock = OUT_ON; //door latched |
dattranvnfrr | 1:ca7bf48a2f71 | 142 | damperRotate(1); //damper opened |
dattranvnfrr | 1:ca7bf48a2f71 | 143 | fanRelay = OUT_ON; //fan on |
dattranvnfrr | 1:ca7bf48a2f71 | 144 | } |
dattranvnfrr | 0:2f5d939d4a4a | 145 | |
dattranvnfrr | 1:ca7bf48a2f71 | 146 | //wait 60sec |
dattranvnfrr | 1:ca7bf48a2f71 | 147 | countDown(60); |
dattranvnfrr | 1:ca7bf48a2f71 | 148 | doorInterlock=OUT_OFF; //door unlatched |
dattranvnfrr | 1:ca7bf48a2f71 | 149 | damperRotate(0); //damper closed |
dattranvnfrr | 1:ca7bf48a2f71 | 150 | fanRelay = OUT_OFF; //fan stops |
dattranvnfrr | 1:ca7bf48a2f71 | 151 | rgbLCD.locate(0,0); |
dattranvnfrr | 1:ca7bf48a2f71 | 152 | rgbLCD.print("Tank is ready! "); |
dattranvnfrr | 1:ca7bf48a2f71 | 153 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 154 | |
dattranvnfrr | 1:ca7bf48a2f71 | 155 | if(doorClosed==IN_ON) //door closed |
dattranvnfrr | 1:ca7bf48a2f71 | 156 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 157 | /* |
dattranvnfrr | 1:ca7bf48a2f71 | 158 | * Get set up for the wash, and wait for the start button |
dattranvnfrr | 1:ca7bf48a2f71 | 159 | */ |
dattranvnfrr | 1:ca7bf48a2f71 | 160 | rgbLCD.locate(0,1); |
dattranvnfrr | 1:ca7bf48a2f71 | 161 | rgbLCD.print("Door closed "); |
dattranvnfrr | 1:ca7bf48a2f71 | 162 | greenRelay = OUT_ON; //green light stays on |
dattranvnfrr | 1:ca7bf48a2f71 | 163 | yellowRelay = OUT_OFF; //yellow light off |
dattranvnfrr | 1:ca7bf48a2f71 | 164 | redRelay = OUT_OFF; //red light off |
dattranvnfrr | 1:ca7bf48a2f71 | 165 | doorInterlock = OUT_OFF; //door unlocked |
dattranvnfrr | 1:ca7bf48a2f71 | 166 | fanRelay = OUT_OFF; |
dattranvnfrr | 1:ca7bf48a2f71 | 167 | while(cycleStartBtt != IN_ON && !(doorClosed == IN_OFF || cancelPending)) |
dattranvnfrr | 1:ca7bf48a2f71 | 168 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 169 | if(stopBtt == IN_ON) |
dattranvnfrr | 1:ca7bf48a2f71 | 170 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 171 | cancelPending = true; |
dattranvnfrr | 1:ca7bf48a2f71 | 172 | continue; |
dattranvnfrr | 1:ca7bf48a2f71 | 173 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 174 | wait(.25); |
dattranvnfrr | 1:ca7bf48a2f71 | 175 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 176 | if(doorClosed == IN_OFF || cancelPending) |
dattranvnfrr | 0:2f5d939d4a4a | 177 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 178 | continue; |
dattranvnfrr | 1:ca7bf48a2f71 | 179 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 180 | |
dattranvnfrr | 1:ca7bf48a2f71 | 181 | |
dattranvnfrr | 1:ca7bf48a2f71 | 182 | /* |
dattranvnfrr | 1:ca7bf48a2f71 | 183 | * Cycle start button pressed - wash for 2 minutes |
dattranvnfrr | 1:ca7bf48a2f71 | 184 | */ |
dattranvnfrr | 1:ca7bf48a2f71 | 185 | rgbLCD.clear(); |
dattranvnfrr | 1:ca7bf48a2f71 | 186 | rgbLCD.locate(0,0); |
dattranvnfrr | 1:ca7bf48a2f71 | 187 | rgbLCD.print("CYCLE STARTED! "); |
dattranvnfrr | 1:ca7bf48a2f71 | 188 | greenRelay = OUT_OFF; //green light off |
dattranvnfrr | 1:ca7bf48a2f71 | 189 | yellowRelay = OUT_ON; //yellow light on |
dattranvnfrr | 1:ca7bf48a2f71 | 190 | fanRelay = OUT_OFF; //fan stop |
dattranvnfrr | 1:ca7bf48a2f71 | 191 | //damperRotate(0); //vent already close |
dattranvnfrr | 1:ca7bf48a2f71 | 192 | |
dattranvnfrr | 1:ca7bf48a2f71 | 193 | if(!simulateMode) |
dattranvnfrr | 1:ca7bf48a2f71 | 194 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 195 | doorInterlock = OUT_ON; //door locked |
dattranvnfrr | 1:ca7bf48a2f71 | 196 | vfd = OUT_ON; //vfd for pump up to speed |
dattranvnfrr | 1:ca7bf48a2f71 | 197 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 198 | countDown(120); //start timer for 2min |
dattranvnfrr | 1:ca7bf48a2f71 | 199 | if(doorClosed == IN_OFF || cancelPending) |
dattranvnfrr | 1:ca7bf48a2f71 | 200 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 201 | continue; |
dattranvnfrr | 1:ca7bf48a2f71 | 202 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 203 | |
dattranvnfrr | 1:ca7bf48a2f71 | 204 | |
dattranvnfrr | 1:ca7bf48a2f71 | 205 | /* |
dattranvnfrr | 1:ca7bf48a2f71 | 206 | * Finished washing - turn off the pump |
dattranvnfrr | 1:ca7bf48a2f71 | 207 | */ |
dattranvnfrr | 1:ca7bf48a2f71 | 208 | vfd = OUT_OFF; //pump off |
dattranvnfrr | 1:ca7bf48a2f71 | 209 | rgbLCD.clear(); |
dattranvnfrr | 1:ca7bf48a2f71 | 210 | rgbLCD.locate(0,0); |
dattranvnfrr | 1:ca7bf48a2f71 | 211 | rgbLCD.print("CYCLE FINISHED! "); |
dattranvnfrr | 1:ca7bf48a2f71 | 212 | wait(1); |
dattranvnfrr | 1:ca7bf48a2f71 | 213 | if(doorClosed == IN_OFF || cancelPending) |
dattranvnfrr | 1:ca7bf48a2f71 | 214 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 215 | continue; |
dattranvnfrr | 0:2f5d939d4a4a | 216 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 217 | |
dattranvnfrr | 1:ca7bf48a2f71 | 218 | |
dattranvnfrr | 1:ca7bf48a2f71 | 219 | /* |
dattranvnfrr | 1:ca7bf48a2f71 | 220 | * Drip dry after washing for 5 minutes |
dattranvnfrr | 1:ca7bf48a2f71 | 221 | */ |
dattranvnfrr | 1:ca7bf48a2f71 | 222 | rgbLCD.clear(); |
dattranvnfrr | 1:ca7bf48a2f71 | 223 | rgbLCD.locate(0,0); |
dattranvnfrr | 1:ca7bf48a2f71 | 224 | rgbLCD.print("DRIP DRYING! "); |
dattranvnfrr | 1:ca7bf48a2f71 | 225 | countDown(300); |
dattranvnfrr | 1:ca7bf48a2f71 | 226 | if(doorClosed == IN_OFF || cancelPending) |
dattranvnfrr | 0:2f5d939d4a4a | 227 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 228 | continue; |
dattranvnfrr | 1:ca7bf48a2f71 | 229 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 230 | |
dattranvnfrr | 1:ca7bf48a2f71 | 231 | |
dattranvnfrr | 1:ca7bf48a2f71 | 232 | /* |
dattranvnfrr | 1:ca7bf48a2f71 | 233 | * Change the air out for 2 minutes |
dattranvnfrr | 1:ca7bf48a2f71 | 234 | */ |
dattranvnfrr | 1:ca7bf48a2f71 | 235 | rgbLCD.clear(); |
dattranvnfrr | 1:ca7bf48a2f71 | 236 | rgbLCD.locate(0,0); |
dattranvnfrr | 1:ca7bf48a2f71 | 237 | rgbLCD.print("AIR CYCLING! "); |
dattranvnfrr | 1:ca7bf48a2f71 | 238 | damperRotate(1); //vent opened |
dattranvnfrr | 1:ca7bf48a2f71 | 239 | if(!simulateMode) |
dattranvnfrr | 1:ca7bf48a2f71 | 240 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 241 | fanRelay = OUT_ON; //fan on |
dattranvnfrr | 1:ca7bf48a2f71 | 242 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 243 | countDown(120); |
dattranvnfrr | 1:ca7bf48a2f71 | 244 | if(doorClosed == IN_OFF || cancelPending) |
dattranvnfrr | 1:ca7bf48a2f71 | 245 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 246 | continue; |
dattranvnfrr | 1:ca7bf48a2f71 | 247 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 248 | |
dattranvnfrr | 1:ca7bf48a2f71 | 249 | |
dattranvnfrr | 1:ca7bf48a2f71 | 250 | /* |
dattranvnfrr | 1:ca7bf48a2f71 | 251 | * Entire cycle is done, close up and go back to waiting |
dattranvnfrr | 1:ca7bf48a2f71 | 252 | */ |
dattranvnfrr | 1:ca7bf48a2f71 | 253 | greenRelay = OUT_ON; //green light on |
dattranvnfrr | 1:ca7bf48a2f71 | 254 | yellowRelay = OUT_OFF; //yellow light off |
dattranvnfrr | 1:ca7bf48a2f71 | 255 | doorInterlock = OUT_OFF; //door unlocked |
dattranvnfrr | 1:ca7bf48a2f71 | 256 | fanRelay = OUT_OFF; //fan off |
dattranvnfrr | 1:ca7bf48a2f71 | 257 | damperRotate(0); //vent closed |
dattranvnfrr | 1:ca7bf48a2f71 | 258 | rgbLCD.clear(); |
dattranvnfrr | 1:ca7bf48a2f71 | 259 | rgbLCD.locate(0,0); |
dattranvnfrr | 1:ca7bf48a2f71 | 260 | rgbLCD.print("Tank is ready! "); |
dattranvnfrr | 0:2f5d939d4a4a | 261 | } |
dattranvnfrr | 0:2f5d939d4a4a | 262 | else //door open |
dattranvnfrr | 0:2f5d939d4a4a | 263 | { |
dattranvnfrr | 0:2f5d939d4a4a | 264 | rgbLCD.locate(0,1); |
dattranvnfrr | 1:ca7bf48a2f71 | 265 | rgbLCD.print("Door open "); |
dattranvnfrr | 1:ca7bf48a2f71 | 266 | greenRelay = OUT_OFF; //green light OFF |
dattranvnfrr | 1:ca7bf48a2f71 | 267 | redRelay = OUT_ON; //turn red light ON |
dattranvnfrr | 1:ca7bf48a2f71 | 268 | yellowRelay = OUT_OFF; |
dattranvnfrr | 1:ca7bf48a2f71 | 269 | damperRotate(1); //damper opened |
dattranvnfrr | 1:ca7bf48a2f71 | 270 | fanRelay = OUT_ON; //fan on |
dattranvnfrr | 0:2f5d939d4a4a | 271 | } |
dattranvnfrr | 0:2f5d939d4a4a | 272 | |
dattranvnfrr | 1:ca7bf48a2f71 | 273 | wait(1); |
dattranvnfrr | 1:ca7bf48a2f71 | 274 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 275 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 276 | |
dattranvnfrr | 1:ca7bf48a2f71 | 277 | |
dattranvnfrr | 1:ca7bf48a2f71 | 278 | |
dattranvnfrr | 1:ca7bf48a2f71 | 279 | |
dattranvnfrr | 1:ca7bf48a2f71 | 280 | void damperRotate(int damper) //damper condition |
dattranvnfrr | 1:ca7bf48a2f71 | 281 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 282 | if(damper==0 && damperIsOpen == true && !simulateMode) |
dattranvnfrr | 1:ca7bf48a2f71 | 283 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 284 | damperRelayAlt=OUT_ON; //toggle damper relay |
dattranvnfrr | 1:ca7bf48a2f71 | 285 | rgbLCD.locate(0,1); |
dattranvnfrr | 1:ca7bf48a2f71 | 286 | rgbLCD.print("Closing damper "); |
dattranvnfrr | 1:ca7bf48a2f71 | 287 | wait(30); |
dattranvnfrr | 1:ca7bf48a2f71 | 288 | damperRelayAlt=OUT_OFF; //time out to reduce wear |
dattranvnfrr | 1:ca7bf48a2f71 | 289 | damperIsOpen = false; |
dattranvnfrr | 1:ca7bf48a2f71 | 290 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 291 | else if(damper == 1 && damperIsOpen == false && !simulateMode) |
dattranvnfrr | 1:ca7bf48a2f71 | 292 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 293 | damperRelay=OUT_ON; //toggle damper relay |
dattranvnfrr | 1:ca7bf48a2f71 | 294 | rgbLCD.locate(0,1); |
dattranvnfrr | 1:ca7bf48a2f71 | 295 | rgbLCD.print("Opening damper "); |
dattranvnfrr | 1:ca7bf48a2f71 | 296 | wait(30); |
dattranvnfrr | 1:ca7bf48a2f71 | 297 | damperRelay=OUT_OFF; //time out to reduce wear |
dattranvnfrr | 1:ca7bf48a2f71 | 298 | damperIsOpen = true; |
dattranvnfrr | 1:ca7bf48a2f71 | 299 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 300 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 301 | |
dattranvnfrr | 1:ca7bf48a2f71 | 302 | void fullLineItoA(int m, char* str) |
dattranvnfrr | 1:ca7bf48a2f71 | 303 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 304 | if(str == NULL) |
dattranvnfrr | 1:ca7bf48a2f71 | 305 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 306 | return; |
dattranvnfrr | 1:ca7bf48a2f71 | 307 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 308 | |
dattranvnfrr | 1:ca7bf48a2f71 | 309 | // Empty the array to 16 white spaces |
dattranvnfrr | 1:ca7bf48a2f71 | 310 | for(int j=0; j < 16; j++) |
dattranvnfrr | 1:ca7bf48a2f71 | 311 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 312 | str[j] = ' '; |
dattranvnfrr | 1:ca7bf48a2f71 | 313 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 314 | str[16] = 0; |
dattranvnfrr | 1:ca7bf48a2f71 | 315 | |
dattranvnfrr | 1:ca7bf48a2f71 | 316 | // Put our counter in it, with the least-significant digit in col 4. |
dattranvnfrr | 1:ca7bf48a2f71 | 317 | int i = 3; |
dattranvnfrr | 1:ca7bf48a2f71 | 318 | do |
dattranvnfrr | 1:ca7bf48a2f71 | 319 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 320 | str[i] = m%10 + '0'; |
dattranvnfrr | 1:ca7bf48a2f71 | 321 | m /= 10; |
dattranvnfrr | 1:ca7bf48a2f71 | 322 | i--; |
dattranvnfrr | 1:ca7bf48a2f71 | 323 | }while(m > 0 && i >= 0); |
dattranvnfrr | 1:ca7bf48a2f71 | 324 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 325 | |
dattranvnfrr | 1:ca7bf48a2f71 | 326 | void countDown(int s) //countdown in sec |
dattranvnfrr | 1:ca7bf48a2f71 | 327 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 328 | int m=0; |
dattranvnfrr | 1:ca7bf48a2f71 | 329 | char count[12]; // make a 'count' string |
dattranvnfrr | 1:ca7bf48a2f71 | 330 | |
dattranvnfrr | 1:ca7bf48a2f71 | 331 | for(m=s; m>0; m--) |
dattranvnfrr | 1:ca7bf48a2f71 | 332 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 333 | if(stopBtt == IN_ON) |
dattranvnfrr | 1:ca7bf48a2f71 | 334 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 335 | cancelPending = true; |
dattranvnfrr | 1:ca7bf48a2f71 | 336 | break; |
dattranvnfrr | 1:ca7bf48a2f71 | 337 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 338 | |
dattranvnfrr | 1:ca7bf48a2f71 | 339 | fullLineItoA(m, count); |
dattranvnfrr | 1:ca7bf48a2f71 | 340 | |
dattranvnfrr | 1:ca7bf48a2f71 | 341 | rgbLCD.locate(0,1); |
dattranvnfrr | 1:ca7bf48a2f71 | 342 | rgbLCD.print(count); |
dattranvnfrr | 1:ca7bf48a2f71 | 343 | |
dattranvnfrr | 1:ca7bf48a2f71 | 344 | wait(1); |
dattranvnfrr | 1:ca7bf48a2f71 | 345 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 346 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 347 | |
dattranvnfrr | 1:ca7bf48a2f71 | 348 | |
dattranvnfrr | 1:ca7bf48a2f71 | 349 | void debugMode() |
dattranvnfrr | 1:ca7bf48a2f71 | 350 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 351 | char displayLine1[17]; |
dattranvnfrr | 1:ca7bf48a2f71 | 352 | char displayLine2[17]; |
dattranvnfrr | 1:ca7bf48a2f71 | 353 | unsigned int count = 0; |
dattranvnfrr | 1:ca7bf48a2f71 | 354 | |
dattranvnfrr | 1:ca7bf48a2f71 | 355 | rgbLCD.clear(); |
dattranvnfrr | 1:ca7bf48a2f71 | 356 | rgbLCD.locate(0,0); |
dattranvnfrr | 1:ca7bf48a2f71 | 357 | //damperRotate(1); |
dattranvnfrr | 1:ca7bf48a2f71 | 358 | |
dattranvnfrr | 1:ca7bf48a2f71 | 359 | do |
dattranvnfrr | 1:ca7bf48a2f71 | 360 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 361 | strcpy(displayLine1, "Door= "); |
dattranvnfrr | 1:ca7bf48a2f71 | 362 | if(doorClosed == 1) |
dattranvnfrr | 1:ca7bf48a2f71 | 363 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 364 | strcat(displayLine1, "1"); |
dattranvnfrr | 1:ca7bf48a2f71 | 365 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 366 | else |
dattranvnfrr | 1:ca7bf48a2f71 | 367 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 368 | strcat(displayLine1, "0"); |
dattranvnfrr | 1:ca7bf48a2f71 | 369 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 370 | |
dattranvnfrr | 1:ca7bf48a2f71 | 371 | strcat(displayLine1, ",Start="); |
dattranvnfrr | 1:ca7bf48a2f71 | 372 | if(cycleStartBtt == 1) |
dattranvnfrr | 1:ca7bf48a2f71 | 373 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 374 | strcat(displayLine1, "1 "); |
dattranvnfrr | 1:ca7bf48a2f71 | 375 | if(stopBtt == 0) |
dattranvnfrr | 1:ca7bf48a2f71 | 376 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 377 | fanRelay = OUT_OFF; |
dattranvnfrr | 1:ca7bf48a2f71 | 378 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 379 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 380 | else |
dattranvnfrr | 1:ca7bf48a2f71 | 381 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 382 | strcat(displayLine1, "0 "); |
dattranvnfrr | 1:ca7bf48a2f71 | 383 | fanRelay = OUT_ON; |
dattranvnfrr | 1:ca7bf48a2f71 | 384 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 385 | |
dattranvnfrr | 1:ca7bf48a2f71 | 386 | |
dattranvnfrr | 1:ca7bf48a2f71 | 387 | strcpy(displayLine2, "Stop= "); |
dattranvnfrr | 1:ca7bf48a2f71 | 388 | if(stopBtt == 1) |
dattranvnfrr | 1:ca7bf48a2f71 | 389 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 390 | strcat(displayLine2, "1 "); |
dattranvnfrr | 1:ca7bf48a2f71 | 391 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 392 | else |
dattranvnfrr | 1:ca7bf48a2f71 | 393 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 394 | strcat(displayLine2, "0 "); |
dattranvnfrr | 1:ca7bf48a2f71 | 395 | |
dattranvnfrr | 1:ca7bf48a2f71 | 396 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 397 | |
dattranvnfrr | 1:ca7bf48a2f71 | 398 | // Every 2s, change the outputs |
dattranvnfrr | 1:ca7bf48a2f71 | 399 | if((count&7) == 0) |
dattranvnfrr | 1:ca7bf48a2f71 | 400 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 401 | doorInterlock = OUT_OFF; //Door interlock |
dattranvnfrr | 1:ca7bf48a2f71 | 402 | //fanRelay = OUT_ON; //Fan control |
dattranvnfrr | 1:ca7bf48a2f71 | 403 | redRelay = OUT_OFF; //Red light |
dattranvnfrr | 1:ca7bf48a2f71 | 404 | yellowRelay = OUT_OFF; //Yellow light |
dattranvnfrr | 1:ca7bf48a2f71 | 405 | greenRelay = OUT_OFF; //Green light |
dattranvnfrr | 1:ca7bf48a2f71 | 406 | damperRelay = OUT_OFF; //Damper solenoid control |
dattranvnfrr | 1:ca7bf48a2f71 | 407 | damperRelayAlt = OUT_OFF; //Damper solenoid toggle control |
dattranvnfrr | 1:ca7bf48a2f71 | 408 | vfd = OUT_OFF; //VFD Start relay |
dattranvnfrr | 1:ca7bf48a2f71 | 409 | |
dattranvnfrr | 1:ca7bf48a2f71 | 410 | switch((count>>3)%8) |
dattranvnfrr | 1:ca7bf48a2f71 | 411 | { |
dattranvnfrr | 1:ca7bf48a2f71 | 412 | case 0: |
dattranvnfrr | 1:ca7bf48a2f71 | 413 | doorInterlock = OUT_ON; //Door interlock |
dattranvnfrr | 1:ca7bf48a2f71 | 414 | strcat(displayLine2, " Lock "); |
dattranvnfrr | 1:ca7bf48a2f71 | 415 | break; |
dattranvnfrr | 1:ca7bf48a2f71 | 416 | case 1: |
dattranvnfrr | 1:ca7bf48a2f71 | 417 | //fanRelay = OUT_ON; //Fan control |
dattranvnfrr | 1:ca7bf48a2f71 | 418 | //strcat(displayLine2, " Fan "); |
dattranvnfrr | 1:ca7bf48a2f71 | 419 | break; |
dattranvnfrr | 1:ca7bf48a2f71 | 420 | case 2: |
dattranvnfrr | 1:ca7bf48a2f71 | 421 | redRelay = OUT_ON; //Red light |
dattranvnfrr | 1:ca7bf48a2f71 | 422 | strcat(displayLine2, " Red "); |
dattranvnfrr | 1:ca7bf48a2f71 | 423 | break; |
dattranvnfrr | 1:ca7bf48a2f71 | 424 | case 3: |
dattranvnfrr | 1:ca7bf48a2f71 | 425 | yellowRelay = OUT_ON; //Yellow light |
dattranvnfrr | 1:ca7bf48a2f71 | 426 | strcat(displayLine2, " Yellow "); |
dattranvnfrr | 1:ca7bf48a2f71 | 427 | break; |
dattranvnfrr | 1:ca7bf48a2f71 | 428 | case 4: |
dattranvnfrr | 1:ca7bf48a2f71 | 429 | greenRelay = OUT_ON; //Green light |
dattranvnfrr | 1:ca7bf48a2f71 | 430 | strcat(displayLine2, " Green "); |
dattranvnfrr | 1:ca7bf48a2f71 | 431 | break; |
dattranvnfrr | 1:ca7bf48a2f71 | 432 | case 5: |
dattranvnfrr | 1:ca7bf48a2f71 | 433 | //damperRelayAlt = OUT_ON; //Damper solenoid toggle control - closed |
dattranvnfrr | 1:ca7bf48a2f71 | 434 | //strcat(displayLine2, " Damper1"); |
dattranvnfrr | 1:ca7bf48a2f71 | 435 | //wait(30); |
dattranvnfrr | 1:ca7bf48a2f71 | 436 | break; |
dattranvnfrr | 1:ca7bf48a2f71 | 437 | case 6: |
dattranvnfrr | 1:ca7bf48a2f71 | 438 | //damperRelay = OUT_ON; //Damper solenoid control - open |
dattranvnfrr | 1:ca7bf48a2f71 | 439 | //strcat(displayLine2, " Damper2"); |
dattranvnfrr | 1:ca7bf48a2f71 | 440 | //wait(30); |
dattranvnfrr | 1:ca7bf48a2f71 | 441 | break; |
dattranvnfrr | 1:ca7bf48a2f71 | 442 | case 7: |
dattranvnfrr | 1:ca7bf48a2f71 | 443 | //vfd = OUT_ON; //VFD Start relay |
dattranvnfrr | 1:ca7bf48a2f71 | 444 | //strcat(displayLine2, " VFD "); |
dattranvnfrr | 1:ca7bf48a2f71 | 445 | break; |
dattranvnfrr | 1:ca7bf48a2f71 | 446 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 447 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 448 | |
dattranvnfrr | 1:ca7bf48a2f71 | 449 | rgbLCD.locate(0,0); |
dattranvnfrr | 1:ca7bf48a2f71 | 450 | rgbLCD.print(displayLine1); |
dattranvnfrr | 1:ca7bf48a2f71 | 451 | rgbLCD.locate(0,1); |
dattranvnfrr | 1:ca7bf48a2f71 | 452 | rgbLCD.print(displayLine2); |
dattranvnfrr | 1:ca7bf48a2f71 | 453 | |
dattranvnfrr | 1:ca7bf48a2f71 | 454 | wait(0.25); |
dattranvnfrr | 1:ca7bf48a2f71 | 455 | count++; |
dattranvnfrr | 1:ca7bf48a2f71 | 456 | } |
dattranvnfrr | 1:ca7bf48a2f71 | 457 | while(cycleStartBtt == IN_OFF || stopBtt == IN_OFF || doorClosed == IN_OFF); |
dattranvnfrr | 0:2f5d939d4a4a | 458 | } |