First draft to the functional spec
Dependencies: mbed Grove_LCD_RGB_Backlight DebounceIn
main.cpp
- Committer:
- dattranvnfrr
- Date:
- 2019-09-18
- Revision:
- 0:2f5d939d4a4a
- Child:
- 1:ca7bf48a2f71
File content as of revision 0:2f5d939d4a4a:
#include "Grove_LCD_RGB_Backlight.h" #include "mbed.h" #include "DebounceIn.h" //input DebounceIn doorClosed(p5); //Check door status DebounceIn cycleStartBtt(p14); //cycle start button InterruptIn stopBtt(p15); //stop button //DigitalIn pot(p20); //output DigitalOut doorInterlock(p6); //Door interlock DigitalOut fanRelay(p7); //Fan control DigitalOut redRelay(p8); //Red light DigitalOut yellowRelay(p11); //Yellow light DigitalOut greenRelay(p12); //Green light DigitalOut damperRelay(p13); //Damper solenoid control DigitalOut damperRelayAlt(p16); //Damper solenoid toggle control DigitalOut vfd(p17); //VFD Start relay Grove_LCD_RGB_Backlight rgbLCD(p9, p10); //Timer display I2C i2c(p9, p10); //Serial pc(USBTX, USBRX); //extern "C" void mbed_reset(); void damperRotate(int damper) //damper condition { if(damper==0) { damperRelayAlt=1; //toggle damper relay wait(5); damperRelayAlt=0; //time out to reduce wear } else //damper==1 { damperRelay=1; //toggle damper relay wait(5); damperRelay=0; //time out to reduce wear } } void countDown(int s) //countdown in sec { int m=0; char cnt[12]; // make a 'count' string for(m=s; m>0; m--) { sprintf(cnt, "%i ", m); rgbLCD.locate(0,1); rgbLCD.print(cnt); wait(1); } } void fullStop() { if(stopBtt==0) { //Display status greenRelay=0; //green light OFF yellowRelay=0; //yellow light OFF redRelay=1; //turn red light ON rgbLCD.clear(); rgbLCD.locate(0,0); rgbLCD.print("CYCLE STOPPED. "); vfd=0; //pump off doorInterlock=1; //door latched wait(2); fanRelay=0; //fan stops damperRotate(0); //damperRelay=0; //damper closed //wait 60sec countDown(10); doorInterlock=0; //door unlatched stopBtt.mode(PullUp); wait(.1); NVIC_SystemReset(); //reset system } } int main() { //on power up status cycleStartBtt.mode(PullUp); wait(.1); doorClosed.mode(PullUp); wait(.1); stopBtt.mode(PullUp); wait(.1); stopBtt.fall(&fullStop); // attach the address of the flip function to the rising edge //check for closed door before running fan while(doorClosed!=0) { rgbLCD.clear(); rgbLCD.locate(0,0); rgbLCD.print("Close the door "); } //Display startup countdown //Startin up and prep the tank rgbLCD.clear(); rgbLCD.setRGB(0x00, 0x66, 0xaa); //set the color rgbLCD.print("Starting up... "); vfd=0; damperRotate(1); //vent opened; doorInterlock=1; fanRelay=1; greenRelay=0; yellowRelay=0; redRelay=0; //start timer for 90sec countDown(5); //Tank is ready rgbLCD.locate(0,0); rgbLCD.print("Tank is ready! "); greenRelay=1; //green light on //doorInterlock=0; //interlock unlatched, ready to load material into the tank fanRelay=0; //fan off while(1) { if(doorClosed==0) //door closed { rgbLCD.locate(0,1); rgbLCD.print("Door closed "); greenRelay=1; //green light stays on yellowRelay=0; //yellow light off redRelay=0; //red light off doorInterlock=0; //door unlocked fanRelay=0; //cycle start button pressed - wash cycle starts if(cycleStartBtt==0) { //Display status rgbLCD.clear(); rgbLCD.locate(0,0); rgbLCD.print("CYCLE STARTED! "); greenRelay=0; //green light off yellowRelay=1; //yellow light on doorInterlock=1; //door locked fanRelay=0; //fan stop damperRotate(0); //vent close vfd=1; //vfd for pump up to speed //Display wash cycle countdown //start timer for 2min countDown(7); //finished washing vfd=0; //pump off //Display status rgbLCD.clear(); rgbLCD.locate(0,0); rgbLCD.print("CYCLE FINISHED! "); countDown(5); //drip dry after washing //Display status rgbLCD.clear(); rgbLCD.locate(0,0); rgbLCD.print("DRIP DRYING! "); //start timer for 5min countDown(10); //Display status rgbLCD.clear(); rgbLCD.locate(0,0); rgbLCD.print("AIR CYCLING! "); damperRotate(1); //vent opened fanRelay=1; //fan on //Display air cycling countdown //start timer for 2min countDown(10); //finished cycling air greenRelay=1; //green light on yellowRelay=0; //yellow light off doorInterlock=0; //door unlocked fanRelay=0; //fan off damperRotate(0); //damperRelay=0; //vent closed //Tank is ready rgbLCD.clear(); rgbLCD.locate(0,0); rgbLCD.print("Tank is ready! "); } /* //Stop button is hit if(stopBtt==1) { //Display status rgbLCD.locate(0,0); rgbLCD.print("CYCLE STOPPED. "); vfd=0; //pump off doorInterlock=1; //door latched wait(2); fanRelay=0; //fan stops damperRotate(0); //damperRelay=0; //damper closed //wait 60sec countDown(10); doorInterlock=0; //door unlatched } */ } else //door open { rgbLCD.locate(0,1); rgbLCD.print("Door opened "); greenRelay=0; //green light OFF redRelay=1; //turn red light ON yellowRelay=0; fanRelay=0; //fan stops damperRotate(1); //damperRelay=1; //damper closed } } }