Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- papaco
- Date:
- 2019-02-11
- Revision:
- 0:b47aaa131075
- Child:
- 1:4fb1de70cd4d
File content as of revision 0:b47aaa131075:
#include "mbed.h" #include "pinout.h" #include "CUTTER.h" #include "EXTRUDER.h" #include "GRIDDLE.h" #include "INTERFACE.h" #include "MACHINE.h" #include "OVEN.h" #include "TORTILLA.h" Ticker timer; INTERFACE interface(StartStopPin,StartStopRPin,StartStopGPin,StartStopBPin,TortillaPin,TempReadyPin); EXTRUDER extruder(ExtruderStartPin,ExtruderPWMPin); CUTTER cutter(CutterUpPin,CutterDownPin,CutterMotorDirectionPin,CutterMotorEnablePin); GRIDDLE griddle(GriddlePWMPin,GriddleUpPin,GriddleDownPin,GriddleHomePin); OVEN oven(OvenPWMPin); MACHINE Lupe(BandPWMPin,TempPin,CapsuleDoorPin,CartridgePin,CuttedPin); TORTILLA DesiredProduction(); #if defined(DEBUG_MODE) static Serial pc(USBTX, USBRX); int DebugTimer=0; #endif void init(void); void MANAGER(void); int STATUS=-1; int GENERAL_TIME=0; int main(){ #if defined(DEBUG_MODE) pc.printf("\n\n***************************\nMCU variable init OK!\r\n"); #endif init(); while(1); }//main void MANAGER(void){ GENERAL_TIME++; /******************************STATUS CONTROL******************************/ if(STATUS==HOME){/****************************************************HOME*/ if(GENERAL_TIME==1){ #if defined(DEBUG_MODE) pc.printf("\nHOME rutine start...\r\n"); #endif interface.setLED(1,1,0); interface.setFlash(true); cutter.down(); extruder.Init(); griddle.Home(); oven.Home(); }//if if(cutter.available()&&griddle.isFree()){ #if defined(DEBUG_MODE) pc.printf("\nHOME rutine end...\r\n"); #endif GENERAL_TIME=-1; STATUS=IDLE; interface.setLED(0,1,0); }//if }else if(STATUS==IDLE){/**********************************************IDLE*/ if(IDLE_TIMER==GENERAL_TIME){ GENERAL_TIME=0; if((Lupe.StartCheck())&&(interface.getFlash())) interface.setFlash(false); if((!Lupe.StartCheck())&&(!interface.getFlash())) interface.setFlash(true); if(interface.getStart()){ #if defined(DEBUG_MODE) pc.printf("\nIDLE Done\r\n"); #endif STATUS=PRODUCTION; GENERAL_TIME=-1; interface.setLED(1,1,1); interface.setFlash(true); }//if }//if }else if(STATUS==PRODUCTION){/**********************************PRODUCTION*/ if(GENERAL_TIME==0){//INIT //DesiredProduction= TORTILLA(interface.getTortilla()); #if defined(DEBUG_MODE) pc.printf("\nProduction of %f Tortillas...\r\n",extruder.getPosition()); #endif }//if if(extruder.getSwitch()){//No dough detected if(extruder.getTimer()>=500){//Check every 0.5s extruder.setTimer(0); extruder.GetHome(); #if defined(DEBUG_MODE) pc.printf("\nExtruder finding home on:%f\r\n",extruder.getPosition()); #endif }//if }else{//Dough detected if((extruder.getTimer()>=5000)&&(extruder.getPosition()>=0.1)){//Check every 5s extruder.setTimer(0); extruder.Step(); #if defined(DEBUG_MODE) pc.printf("\nExtruder position:%f\r\n",extruder.getPosition()); #endif }//if }//else if(extruder.getPosition()>=0.1){ //EXTRUDER_PRODUCTION=true; #if defined(DEBUG_MODE) pc.printf("\nExtruder reached end position\r\n"); #endif GENERAL_TIME=-1; STATUS=HOME; interface.setLED(1,1,0); interface.setFlash(true); }//if }//else if /*****************************GENERAL CONTROL******************************/ /*************************GENERAL INTERFACE CONTROL************************/ //Flash Control interface.check(); /*************************GENERAL MACHINE CONTROL**************************/ /*************************GENERAL CUTTER CONTROL***************************/ cutter.check(); /*************************GENERAL EXTRUDER CONTROL*************************/ extruder.check(); /*************************GENERAL GRIDDLE CONTROL**************************/ if(griddle.check()){ #if defined(DEBUG_MODE) pc.printf("\nGriddle moving\r\n"); #endif }//if /*************************GENERAL OVEN CONTROL*****************************/ return; }//MANAGER void init(void){ #if defined(DEBUG_MODE) pc.printf("\nMachine modules is starting...\r\n"); #endif interface.Init(); #if defined(DEBUG_MODE) pc.printf("INTERFACE OK!\r\n"); #endif Lupe.Init(); #if defined(DEBUG_MODE) pc.printf("MACHINE OK!\r\n"); #endif cutter.Init(); #if defined(DEBUG_MODE) pc.printf("CUTTER OK!\r\n"); #endif extruder.Init(); #if defined(DEBUG_MODE) pc.printf("EXTRUDER OK!\r\n"); #endif griddle.Init(); #if defined(DEBUG_MODE) pc.printf("GRIDDLE OK!\r\n"); #endif oven.Init(); #if defined(DEBUG_MODE) pc.printf("OVEN OK!\r\n"); #endif timer.attach(&MANAGER,0.001); #if defined(DEBUG_MODE) pc.printf("Time Manager OK!\r\n"); #endif wait(5); #if defined(DEBUG_MODE) pc.printf("\nInit process done...\r\n"); #endif STATUS=HOME; GENERAL_TIME=0; return; }//init