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