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
functions.h
00001 #ifndef FUCTIONS_H 00002 #define FUNCTIONS_H 00003 00004 #include "colors.c" 00005 #include "mbed.h" 00006 #include "Output.h" 00007 #include "Shifter.h" 00008 #include "LCD_DISCO_F469NI.h" 00009 00010 LCD_DISCO_F469NI lcd; 00011 TS_DISCO_F469NI ts; 00012 uint16_t X, Y; 00013 uint8_t status; 00014 uint8_t cleared = 0; 00015 uint8_t prev_nb_touches = 0; 00016 uint8_t text[30]; 00017 00018 TS_StateTypeDef TS_State; 00019 00020 Serial pc(SERIAL_TX, SERIAL_RX); 00021 //MAX31865_RTD( ptd_type type,PinName mosi, PinName miso, PinName sclk, PinName nss); 00022 MAX31865_RTD PT1(MAX31865_RTD::RTD_PT100, D11, D12, D13, A0); 00023 MAX31865_RTD PT2(MAX31865_RTD::RTD_PT100, D11, D12, D13, A1); 00024 MAX31865_RTD PT3(MAX31865_RTD::RTD_PT100, D11, D12, D13, A2); 00025 00026 int temp_safe=150; 00027 float setpointLOW = 430; 00028 float setpointHIGH = 450; 00029 int clean_time=7200; 00030 int tempo =1200; 00031 int temperatura_roast = 250; 00032 00033 /// dichiarazione variabili //////////////////////////////////////////////////// 00034 //per i sensori 00035 static bool myDataIn[8] = {1,0,1,0,1,0,1,0}; 00036 //myDataIn[0] tappo caffè chiuso; 00037 //myDataIn[1] sensore porta chiusa; 00038 //myDataIn[2] finecorsa sarico aperto; 00039 //myDataIn[3] finecorsa scarico chiuso; 00040 //myDataIn[4]; //da dare un nome 00041 //myDataIn[5]; //da dare un nome 00042 //myDataIn[6]; //da dare un nome 00043 //myDataIn[7]; //da dare un nome 00044 00045 //per i relay 00046 Shifter scheda_8relay; //!! pinout defined in library 00047 Output Bloccoporta; // 00048 Output Giracaffe; // palette agita caffé 00049 Output Lampadina; // Lampadina 00050 Output VTangenziale; // 1 00051 Output VRadiale; // 2 00052 Output Scarico_caffe; // motore scarico caffé 00053 Output Resistenza1; // 00054 Output Resistenza2; // 00055 Output Ventola; // cooling 00056 00057 bool Activate_Door; //sul SSR per comandare il bloccoporta 00058 enum {STOP, CLEAN, ROAST, PULSANTI, CLEAN_ATTIVO, ROAST_PRE, ROAST_ACTIVE}; 00059 /// funzioni /////////////////////////////////////////////////////////////////// 00060 //------------------------------------------------------------------------------ 00061 void disegna_pulsanti(int pulsante) 00062 { 00063 int riga, colonna, contatore=0; 00064 switch (pulsante) { 00065 case 0: //STOP 00066 contatore=0; 00067 for (riga=0; riga<120; riga++) { 00068 for ( colonna=0; colonna<120; colonna++) { 00069 lcd.DrawPixel (20+colonna, 20+ riga, _acAPower[contatore]); 00070 contatore++; 00071 } 00072 colonna=0; 00073 } 00074 //lcd.DrawRect (20, 20, 120, 120); 00075 break; 00076 case 1: //CLEAN 00077 contatore=0; 00078 for (riga=0; riga<120; riga++) { 00079 for ( colonna=0; colonna<120; colonna++) { 00080 lcd.DrawPixel (20+colonna, 165+ riga, _acAClean_0[contatore]); 00081 contatore++; 00082 } 00083 colonna=0; 00084 } 00085 //lcd.DrawRect (20, 165, 120, 120); 00086 break; 00087 case 2: //ROAST 00088 contatore=0; 00089 for (riga=0; riga<120; riga++) { 00090 for ( colonna=0; colonna<120; colonna++) { 00091 lcd.DrawPixel (20+colonna, 290+ riga, _acARoast_0[contatore]); 00092 contatore++; 00093 } 00094 colonna=0; 00095 } 00096 //lcd.DrawRect (20, 290, 120, 120); 00097 break; 00098 case 3: //pulsanti regolazione tempo e temperatura 00099 for (riga=0; riga<140; riga++) { 00100 for ( colonna=0; colonna<200; colonna++) { 00101 lcd.DrawPixel (180+colonna, 270+ riga, _acAPulsanti[contatore]); 00102 contatore++; 00103 } 00104 colonna=0; 00105 } 00106 break; 00107 case 4: //CLEAN ATTIVO 00108 contatore=0; 00109 for (riga=0; riga<120; riga++) { 00110 for ( colonna=0; colonna<120; colonna++) { 00111 lcd.DrawPixel (20+colonna, 165+ riga, _acAClean_1[contatore]); 00112 contatore++; 00113 } 00114 colonna=0; 00115 } 00116 //lcd.DrawRect (20, 165, 120, 120); 00117 break; 00118 case 5: //ROAST PRE 00119 contatore=0; 00120 for (riga=0; riga<120; riga++) { 00121 for ( colonna=0; colonna<120; colonna++) { 00122 lcd.DrawPixel (20+colonna, 290+ riga, _acARoast_1[contatore]); 00123 contatore++; 00124 } 00125 colonna=0; 00126 } 00127 //lcd.DrawRect (20, 290, 120, 120); 00128 break; 00129 case 6: //ROAST ACTIVE 00130 contatore=0; 00131 for (riga=0; riga<120; riga++) { 00132 for ( colonna=0; colonna<120; colonna++) { 00133 lcd.DrawPixel (20+colonna, 290+ riga, _acARoast_2[contatore]); 00134 contatore++; 00135 } 00136 colonna=0; 00137 } 00138 //lcd.DrawRect (20, 290, 120, 120); 00139 break; 00140 } 00141 } 00142 00143 bool setup_griglia() 00144 { 00145 lcd.Clear(light_sky_blue); 00146 lcd.SetBackColor(light_sky_blue); 00147 lcd.SetFont(&Font24); 00148 lcd.SetTextColor(black); 00149 lcd.DisplayStringAt(670, LINE(0), (uint8_t *)"Ver 1.0", LEFT_MODE); 00150 // disegno bottoni 00151 disegna_pulsanti(STOP); 00152 disegna_pulsanti(CLEAN); 00153 disegna_pulsanti(ROAST); 00154 disegna_pulsanti(PULSANTI); 00155 00156 //lcd.DrawRect (180, 270, 200, 140); 00157 //lcd.DrawRect (220, 270, 60, 60); 00158 //lcd.DrawRect (325, 270, 60, 60); 00159 //lcd.DrawRect (220, 350, 60, 60); 00160 //lcd.DrawRect (325, 350, 60, 60); 00161 00162 lcd.DisplayStringAt(200, LINE( 8), (uint8_t *)"Time:", LEFT_MODE); 00163 lcd.DisplayStringAt(330, LINE(8), (uint8_t *)"'", LEFT_MODE); 00164 lcd.DisplayStringAt(385, LINE(8), (uint8_t *)"''", LEFT_MODE); 00165 lcd.DisplayStringAt(200, LINE( 10), (uint8_t *)"Temp:", LEFT_MODE); 00166 lcd.DrawCircle(355, LINE(10)+3, 4); 00167 lcd.DisplayStringAt(360, LINE( 10), (uint8_t *)"C", LEFT_MODE); 00168 lcd.DisplayStringAt(620, LINE( 9), (uint8_t *)"T1:", LEFT_MODE); 00169 lcd.DisplayStringAt(620, LINE(11), (uint8_t *)"T2:", LEFT_MODE); 00170 lcd.DisplayStringAt(620, LINE(13), (uint8_t *)"T3:", LEFT_MODE); 00171 00172 //per prova, da togliere dopo 00173 lcd.SetTextColor(red); 00174 lcd.FillRect (620, 20, 70, 70); 00175 lcd.SetTextColor(green); 00176 lcd.FillRect (620, 100, 70, 70); 00177 lcd.SetTextColor(black); 00178 //fino qui 00179 00180 PT1.configure( true, true, false, false, MAX31865_FAULT_DETECTION_NONE, 00181 true, true, 0x0000, 0x7fff ); 00182 PT2.configure( true, true, false, false, MAX31865_FAULT_DETECTION_NONE, 00183 true, true, 0x0000, 0x7fff ); 00184 PT3.configure( true, true, false, false, MAX31865_FAULT_DETECTION_NONE, 00185 true, true, 0x0000, 0x7fff ); 00186 00187 return 0; 00188 } 00189 //------------------------------------------------------------------------------ 00190 bool * getData() 00191 { 00192 //define where your pins are 00193 DigitalOut latchPin(D7); 00194 DigitalOut clockPin(D6); 00195 DigitalIn dataPin(D5); 00196 float tempoattesa = 20; 00197 //acquiring values 00198 latchPin.write(1); 00199 wait_us(tempoattesa); 00200 //read values acquired and store in array 00201 latchPin.write(0); 00202 for (int i=7; i>=0; i--) { 00203 wait_us(tempoattesa); 00204 clockPin.write(0); 00205 wait_us(tempoattesa); 00206 myDataIn[i] = dataPin.read(); //1 if OT open, 0 if OT close 00207 clockPin.write(1); 00208 } 00209 //per prova da togliere dopo 00210 for (int i=7; i>=0; i--) { // D7,D6,.....,D1,D0 00211 sprintf((char*)text, "%d", myDataIn[0+i]); 00212 lcd.DisplayStringAt(580+20*i,LINE(8), (uint8_t *)&text, LEFT_MODE); 00213 } 00214 // 00215 return myDataIn; 00216 } 00217 //------------------------------------------------------------------------------ 00218 void object_update() 00219 { 00220 //update delle immagini e dello stato delle uscite 00221 Lampadina.draw_image (&_acLampadina_acceso[0], &_acLampadina_spento[0], Lampadina.stato, 230, 20); 00222 Resistenza1.draw_image (&_acResistenza1_acceso[0], &_acResistenza1_spento[0], Resistenza1.stato, 300, 20); 00223 Resistenza2.draw_image (&_acResistenza2_acceso[0], &_acResistenza2_spento[0], Resistenza2.stato, 370, 20); 00224 Giracaffe.draw_image (&_acGiracaffe_acceso[0], &_acGiracaffe_spento[0], Giracaffe.stato, 440, 20); 00225 Bloccoporta.draw_image (&_acPorta_aperto[0], &_acPorta_chiuso[0], Bloccoporta.stato, 230, 90); 00226 VTangenziale.draw_image (&_acVTangenziale_acceso[0], &_acVTangenziale_spento[0], VTangenziale.stato, 300, 90); 00227 VRadiale.draw_image (&_acVRadiale_acceso[0], &_acVRadiale_spento[0], VRadiale.stato, 370, 90); 00228 Ventola.draw_image (&_acVentola_acceso[0], &_acVentola_spento[0], Ventola.stato, 440, 90); 00229 //update uscita 74HC595 00230 bool array[16]= {!Lampadina.stato, !Giracaffe.stato, !VTangenziale.stato, !Resistenza1.stato, !Resistenza2.stato, !VRadiale.stato, !Scarico_caffe.ON_OFF, !Scarico_caffe.CW_CCW, !Ventola.stato, Activate_Door,1,1,1,1,1,1}; 00231 for (int i=0; i<16; i++) scheda_8relay.setPin(i,array[i]); 00232 scheda_8relay.write(); 00233 } 00234 //------------------------------------------------------------------------------ 00235 void temperature_update() 00236 { 00237 lcd.DisplayStringAt(680, LINE(9), (uint8_t *)" ", LEFT_MODE); 00238 lcd.DisplayStringAt(680, LINE(11), (uint8_t *)" ", LEFT_MODE); 00239 lcd.DisplayStringAt(680, LINE(13), (uint8_t *)" ", LEFT_MODE); 00240 PT1.read_all( ); 00241 if (PT1.temperature( )>150) lcd.SetTextColor(red); 00242 else lcd.SetTextColor(black); 00243 sprintf((char*)text, "%1.0f", PT1.temperature( )); 00244 lcd.DisplayStringAt(680, LINE(9), (uint8_t *)&text, LEFT_MODE); 00245 PT2.read_all( ); 00246 if (PT2.temperature( )>150) lcd.SetTextColor(red); 00247 else lcd.SetTextColor(black); 00248 sprintf((char*)text, "%1.0f", PT2.temperature( )); 00249 lcd.DisplayStringAt(680, LINE(11), (uint8_t *)&text, LEFT_MODE); 00250 PT3.read_all( ); 00251 if (PT3.temperature( )>150) lcd.SetTextColor(red); 00252 else lcd.SetTextColor(black); 00253 sprintf((char*)text, "%1.0f", PT3.temperature( )); 00254 lcd.DisplayStringAt(680, LINE(13), (uint8_t *)&text, LEFT_MODE); 00255 lcd.SetTextColor(black); 00256 00257 //per sicurezza la temperatura non può superare i 450 gradi 00258 if (PT1.temperature( )>450 || PT2.temperature( )>450) { 00259 Resistenza1_spento(); 00260 Resistenza2_spento(); 00261 } 00262 } 00263 00264 //------------------------------------------------------------------------------ 00265 /// Lampadina 00266 void Lampadina_acceso() 00267 { 00268 Lampadina.stato=1; 00269 object_update(); 00270 } 00271 void Lampadina_spento() 00272 { 00273 Lampadina.stato=0; 00274 object_update(); 00275 } 00276 //------------------------------------------------------------------------------ 00277 /// Resistenza 1 00278 void Resistenza1_acceso() 00279 { 00280 Resistenza1.stato=1; 00281 object_update(); 00282 } 00283 void Resistenza1_spento() 00284 { 00285 Resistenza1.stato=0; 00286 object_update(); 00287 } 00288 //------------------------------------------------------------------------------ 00289 /// Resistenza 2 00290 void Resistenza2_acceso() 00291 { 00292 Resistenza2.stato=1; 00293 object_update(); 00294 } 00295 void Resistenza2_spento() 00296 { 00297 Resistenza2.stato=0; 00298 object_update(); 00299 } 00300 //------------------------------------------------------------------------------ 00301 /// Ventola 12/24 volt 00302 void Ventola_acceso() 00303 { 00304 Ventola.stato=1; 00305 object_update(); 00306 } 00307 void Ventola_spento() 00308 { 00309 Ventola.stato=0; 00310 object_update(); 00311 } 00312 //------------------------------------------------------------------------------ 00313 /// Ventola Radiale 00314 void VRadiale_acceso() 00315 { 00316 VRadiale.stato=1; 00317 object_update(); 00318 } 00319 void VRadiale_spento() 00320 { 00321 VRadiale.stato=0; 00322 object_update(); 00323 } 00324 //------------------------------------------------------------------------------ 00325 /// Ventola Tangenziale 00326 void VTangenziale_acceso() 00327 { 00328 VTangenziale.stato=1; 00329 object_update(); 00330 } 00331 void VTangenziale_spento() 00332 { 00333 VTangenziale.stato=0; 00334 object_update(); 00335 } 00336 //------------------------------------------------------------------------------ 00337 /// Giracaffe 00338 void Giracaffe_acceso() 00339 { 00340 Giracaffe.stato=1; 00341 object_update(); 00342 } 00343 void Giracaffe_spento() 00344 { 00345 Giracaffe.stato=0; 00346 object_update(); 00347 } 00348 //------------------------------------------------------------------------------ 00349 ///Apro scarico caffe 00350 bool Apro_scarico() 00351 { 00352 do { 00353 lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"COFFE UNLOAD IS OPENING ", LEFT_MODE); 00354 Scarico_caffe.CW_CCW=1; 00355 object_update(); 00356 wait(0.5); 00357 Scarico_caffe.ON_OFF=1; 00358 object_update(); 00359 getData(); 00360 } while(!myDataIn[2]); 00361 Scarico_caffe.ON_OFF=0; 00362 lcd.DisplayStringAt(10, LINE(18), (uint8_t *)" ", LEFT_MODE); 00363 wait(0.4); 00364 return 0; 00365 } 00366 ///Chiudo scarico 00367 bool Chiudo_scarico() 00368 { 00369 do { 00370 lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"COFFE UNLOAD IS CLOSING ", LEFT_MODE); 00371 Scarico_caffe.CW_CCW=0; 00372 object_update(); 00373 wait(0.5); 00374 Scarico_caffe.ON_OFF=1; 00375 object_update(); 00376 getData(); 00377 } while(!myDataIn[3]); 00378 Scarico_caffe.ON_OFF=0; 00379 lcd.DisplayStringAt(10, LINE(18), (uint8_t *)" ", LEFT_MODE); 00380 wait(0.4); 00381 return 0; 00382 } 00383 //------------------------------------------------------------------------------ 00384 ///Porta 00385 bool apro_porta() 00386 { 00387 do { 00388 temperature_update(); 00389 lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"TEMPERATURE ABOVE T-SAFE ", LEFT_MODE); 00390 } while (PT1.temperature( )>temp_safe+5); 00391 //attivazione del relay 00392 Activate_Door=0; 00393 object_update(); 00394 wait(0.100); 00395 Activate_Door=1; 00396 object_update(); 00397 wait(0.050); 00398 Activate_Door=0; 00399 object_update(); 00400 wait(0.200); 00401 Activate_Door=1; 00402 object_update(); 00403 wait(0.050); 00404 Activate_Door=0; 00405 object_update(); 00406 /// 00407 lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"DOOR IS OPEN ", LEFT_MODE); 00408 wait(1.0); 00409 lcd.DisplayStringAt(10, LINE(18), (uint8_t *)" ", LEFT_MODE); 00410 Bloccoporta.stato=0; 00411 object_update(); 00412 return 0; 00413 } 00414 bool chiudo_porta() 00415 { 00416 do { 00417 } while (!Chiudo_scarico()); 00418 do { 00419 getData(); 00420 lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"CLOSE THE COFFE COVER ", LEFT_MODE); 00421 wait(0.1); 00422 } while (!myDataIn[0]); 00423 do { 00424 getData(); 00425 lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"CLOSE THE DOOR ", LEFT_MODE); 00426 wait(0.1); 00427 } while (!myDataIn[1]); //NB porta chiusa lo stato logico è =1, se è aperta lo stato logico è 0 e il ciclo while, finatanto che, non è fatto, ecco il perchè della negazione 00428 //attivazione del relay per chiudere la porta 00429 Activate_Door=0; 00430 object_update(); 00431 wait(0.100); 00432 Activate_Door=1; 00433 object_update(); 00434 wait(0.050); 00435 Activate_Door=0; 00436 object_update(); 00437 wait(0.100); 00438 /// 00439 lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"DOOR IS CLOSED ", LEFT_MODE); 00440 Bloccoporta.stato=1; 00441 object_update(); 00442 wait(1.200); 00443 lcd.DisplayStringAt(10, LINE(18), (uint8_t *)" ", LEFT_MODE); 00444 return 0; 00445 } 00446 //End of Functions// 00447 #endif
Generated on Wed Jul 13 2022 01:30:13 by
