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.
Dependencies: BSP_DISCO_F469NI LCD_DISCO_F469NI Shifter2 TS_DISCO_F469NI max31865 mbed
main.cpp
00001 #include "mbed.h" 00002 #include "TS_DISCO_F469NI.h" 00003 #include "LCD_DISCO_F469NI.h" 00004 #include "MAX31865.h" 00005 00006 #include "AClean_0.c" 00007 #include "AClean_1.c" 00008 #include "ARoast_0.c" 00009 #include "ARoast_1.c" 00010 #include "ARoast_2.c" 00011 #include "APower.c" 00012 00013 #include "APulsanti.c" 00014 #include "Porta_aperto.c" 00015 #include "Porta_chiuso.c" 00016 #include "Giracaffe_acceso.c" 00017 #include "Giracaffe_spento.c" 00018 #include "Lampadina_acceso.c" 00019 #include "Lampadina_spento.c" 00020 #include "VTangenziale_acceso.c" 00021 #include "VTangenziale_spento.c" 00022 #include "VRadiale_acceso.c" 00023 #include "VRadiale_spento.c" 00024 #include "Resistenza1_acceso.c" 00025 #include "Resistenza1_spento.c" 00026 #include "Resistenza2_acceso.c" 00027 #include "Resistenza2_spento.c" 00028 #include "Ventola_acceso.c" 00029 #include "Ventola_spento.c" 00030 00031 #include "functions.h" 00032 #include "colors.c" 00033 #include "Output.h" 00034 00035 extern void clean(int, float, float); 00036 extern void roast(int, int); 00037 extern void stop(bool); 00038 00039 extern void temperature_update(); 00040 00041 bool stato_porta=0; //da cancellare, solo per prova porta 00042 bool isPreRoastFinished=0; 00043 00044 int main() 00045 { 00046 setup_griglia(); //setup, parte grafica 00047 00048 while(1) { 00049 getData(); 00050 temperature_update(); 00051 //acquisisco la pressione sullo schermo per attivare i vari oggetti 00052 ts.GetState(&TS_State); 00053 X = TS_State.touchX[0]; //acquisisco la X 00054 Y = TS_State.touchY[0]; //acquisisco la Y 00055 00056 //------------------------------------------------------------------------------ 00057 ///solo per prova 00058 if ((TS_State.touchDetected) && (X>=230 && X<300 && Y>=20 && Y<90)) { 00059 Lampadina.stato=!Lampadina.stato; 00060 object_update(); 00061 } 00062 if ((TS_State.touchDetected) && (X>=300 && X<370 && Y>=20 && Y<90)) { 00063 Resistenza1.stato=!Resistenza1.stato; 00064 object_update(); 00065 } 00066 if ((TS_State.touchDetected) && (X>=370 && X<440 && Y>=20 && Y<90)) { 00067 Resistenza2.stato=!Resistenza2.stato; 00068 object_update(); 00069 } 00070 if ((TS_State.touchDetected) && (X>=440 && X<510 && Y>=20 && Y<90)) { 00071 Giracaffe.stato=!Giracaffe.stato; 00072 object_update(); 00073 } 00074 if ((TS_State.touchDetected) && (X>=230 && X<300 && Y>=90 && Y<160)) { 00075 stato_porta=!stato_porta; 00076 (stato_porta==1) ? chiudo_porta() : apro_porta(); 00077 } 00078 if ((TS_State.touchDetected) && (X>=300 && X<370 && Y>=90 && Y<160)) { 00079 VTangenziale.stato=!VTangenziale.stato; 00080 object_update(); 00081 } 00082 if ((TS_State.touchDetected) && (X>=370 && X<440 && Y>=90 && Y<160)) { 00083 VRadiale.stato=!VRadiale.stato; 00084 object_update(); 00085 } 00086 if ((TS_State.touchDetected) && (X>=440 && X<510 && Y>=90 && Y<160)) { 00087 Ventola.stato=!Ventola.stato; 00088 object_update(); 00089 } 00090 if ((TS_State.touchDetected) && (X>=620 && X<690 && Y>=20 && Y<90)) { 00091 Apro_scarico(); 00092 } 00093 if ((TS_State.touchDetected) && (X>=620 && X<690 && Y>=100 && Y<170)) { 00094 Chiudo_scarico(); 00095 } 00096 //------------------------------------------------------------------------------ 00097 //if ROAST pressed 00098 if ((TS_State.touchDetected) && (X>=20 && X<140 && Y>=290 && Y<410)) { 00099 roast(temperatura_roast,tempo); 00100 } 00101 //if CLEAN pressed 00102 if ((TS_State.touchDetected) && (X>=20 && X<140 && Y>=165 && Y<285)) { 00103 clean(clean_time, setpointLOW, setpointHIGH); 00104 } 00105 //if STOP pressed 00106 if ((TS_State.touchDetected) && (X>=20 && X<140 && Y>=20 && Y<140)) { 00107 stop(1); 00108 } 00109 //if TEMPERATURA UPPER pressed 00110 if ((TS_State.touchDetected) && (X>=200 && X<260 && Y>=270 && Y<330)) { 00111 temperatura = temperatura+5; 00112 if (temperatura >300) temperatura =300; 00113 } 00114 //if TEMPERATURA LOWER pressed 00115 if ((TS_State.touchDetected) && (X>=200 && X<260 && Y>=350 && Y<410)) { 00116 temperatura = temperatura-5; 00117 if (temperatura <150) temperatura =150; 00118 } 00119 //if TEMPO UPPER pressed 00120 if ((TS_State.touchDetected) && (X>=325 && X<385 && Y>=270 && Y<330)) { 00121 tempo = tempo+15; 00122 if (tempo >3000) tempo =3000; 00123 } 00124 //if TEMPO LOWER pressed 00125 if ((TS_State.touchDetected) && (X>=325 && X<385 && Y>=350 && Y<410)) { 00126 tempo = tempo-15; 00127 if (tempo <120) tempo =120; 00128 } 00129 //------------------------------------------------------------------------------ 00130 //scrivo minuti e secondi 00131 int minuti = tempo/60; 00132 int secondi = tempo%60; 00133 sprintf((char*)text, "%2d", minuti); 00134 lcd.DisplayStringAt(295,LINE(8), (uint8_t *)&text, LEFT_MODE); 00135 sprintf((char*)text, "%2d", secondi); 00136 lcd.DisplayStringAt(350,LINE(8), (uint8_t *)&text, LEFT_MODE); 00137 //scrivo temperatura 00138 sprintf((char*)text, "%3d", temperatura); 00139 lcd.DisplayStringAt(295,LINE(10), (uint8_t *)&text, LEFT_MODE); 00140 //------------------------------------------------------------------------------ 00141 object_update(); 00142 wait(0.1); 00143 }//close while(1) 00144 }//close main 00145 00146 //CLEAN 00147 void clean(int clean_time, float setpointLOW, float setpointHIGH) 00148 { 00149 disegna_pulsanti(CLEAN_ATTIVO); 00150 Lampadina_spento(); 00151 Ventola_spento(); 00152 VRadiale_spento(); 00153 VTangenziale_acceso(); 00154 Giracaffe_spento(); 00155 Resistenza1_spento(); 00156 Resistenza2_spento(); 00157 Chiudo_scarico(); //chiudo lo scarico del caffè 00158 //non procedo fino a quando la porta non è chiusa e anche il tappo del caffè 00159 do { 00160 /// 00161 } while (!chiudo_porta()); 00162 00163 lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"CLEAN ACTIVE ", LEFT_MODE); 00164 Timer timer; 00165 timer.start(); 00166 int previous_time, actual_time; 00167 previous_time = timer.read(); 00168 VRadiale_acceso(); 00169 while(1) { 00170 actual_time = timer.read(); 00171 uint8_t text[30]; 00172 //acquisisco la pressione sullo schermo per vedere se devo stoppare il ciclo mentre faccio il clean 00173 ts.GetState(&TS_State); 00174 int X = TS_State.touchX[0]; 00175 int Y = TS_State.touchY[0]; 00176 if ((TS_State.touchDetected) && (X>=20 && X<140 && Y>=235 && Y<335)) { //STOP 00177 stop(0); 00178 break; 00179 } 00180 //se la temperatura è sotto il setpoint high continuo a riscaldare, se la temperatura scende sotto il setpoint low ricomincio a riscaldare 00181 temperature_update(); 00182 if (PT1.temperature( )<=setpointLOW) { 00183 Resistenza1_acceso(); 00184 Resistenza2_acceso(); 00185 } 00186 if (PT1.temperature( )>setpointHIGH) { 00187 Resistenza1_spento(); 00188 Resistenza2_spento(); 00189 } 00190 //countdown dal clean_time a zero 00191 if (actual_time-previous_time >=1) { 00192 lcd.SetTextColor(black); 00193 sprintf((char*)text, "%5d", clean_time); 00194 lcd.DisplayStringAt(210,LINE(18), (uint8_t *)&text, LEFT_MODE); 00195 previous_time = actual_time; 00196 clean_time--; 00197 } 00198 //se il tempo di clean è finito avvio la procedura di stop 00199 if (clean_time<0) { 00200 stop(0); 00201 break; 00202 } 00203 } 00204 } 00205 00206 //STOP procedura di stop 00207 void stop(bool clean_roast) 00208 { 00209 //stop(0) se era in esecuzione il cleaning 00210 //stop(1) se era in esecuzione il roasting 00211 lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"STOP ", LEFT_MODE); 00212 lcd.DisplayStringAt(260,LINE(18), (uint8_t *)" ", LEFT_MODE); 00213 //spengo le resistenze 00214 Resistenza1_spento(); 00215 Resistenza2_spento(); 00216 do { 00217 temperature_update(); 00218 lcd.SetTextColor(red); 00219 lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"TEMPERATURE ABOVE 150", LEFT_MODE); 00220 wait (2.0); 00221 lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"NOT POSSIBLE TO OPEN DOOR", LEFT_MODE); 00222 wait (2.0); 00223 lcd.DisplayStringAt(10, LINE(18), (uint8_t *)" ", LEFT_MODE); 00224 wait (2.0); 00225 lcd.SetTextColor(black); 00226 } while (PT1.temperature( )>temp_safe); 00227 wait (5.0); 00228 00229 //spengo tutto 00230 VRadiale_spento(); 00231 VTangenziale_spento(); 00232 Lampadina_spento(); 00233 //scarico caffe 00234 if (clean_roast) { 00235 Apro_scarico(); 00236 Ventola_acceso(); 00237 Giracaffe_acceso(); 00238 wait (10); 00239 Giracaffe_spento(); 00240 wait(290); 00241 } 00242 Ventola_spento(); 00243 Giracaffe_spento(); 00244 //apertura porta 00245 apro_porta(); 00246 } 00247 00248 //ROAST 00249 void roast (int roast_temp, int roast_time) 00250 { 00251 disegna_pulsanti(ROAST_PRE); 00252 Timer timer; 00253 int previous_time, actual_time; 00254 Lampadina_acceso(); 00255 Ventola_spento(); 00256 VRadiale_spento(); 00257 VTangenziale_acceso(); 00258 Giracaffe_spento(); 00259 Resistenza1_spento(); 00260 Resistenza2_spento(); 00261 Chiudo_scarico(); //chiudo lo scarico del caffè 00262 //non procedo fino a quando la porta non è chiusa e anche il tappo del caffè 00263 do { 00264 /// 00265 } while (!chiudo_porta()); 00266 temperature_update(); 00267 if (PT1.temperature( )<=roast_temp-10) { 00268 Resistenza1_acceso(); 00269 Resistenza2_acceso(); 00270 } 00271 if (PT1.temperature( )>roast_temp+10) { 00272 Resistenza1_spento(); 00273 disegna_pulsanti(ROAST_ACTIVE); 00274 if (!isPreRoastFinished) { 00275 disegna_pulsanti(ROAST_ACTIVE); 00276 timer.start(); 00277 previous_time = timer.read(); 00278 isPreRoastFinished=1; 00279 } 00280 } 00281 00282 }
Generated on Wed Jul 13 2022 01:30:13 by
