new version of AL96_OT

Dependencies:   mbed LCD_DISCO_F469NI TS_DISCO_F469NI BSP_DISCO_F469NI

Revision:
2:ee10ee4002d5
Parent:
1:309cda84edd4
--- a/functions.h	Fri Jun 01 10:56:20 2018 +0000
+++ b/functions.h	Mon May 18 19:00:39 2020 +0000
@@ -1,168 +1,36 @@
 #ifndef FUCTIONS_H
 #define FUNCTIONS_H
 
-#include "colors.c"
-#include "mbed.h"
-#include "Output.h"
-#include "Shifter.h"
-#include "LCD_DISCO_F469NI.h"
-#include "display.h"
-
-Serial pc(SERIAL_TX, SERIAL_RX);
-//MAX31865_RTD( ptd_type type,PinName mosi, PinName miso, PinName sclk, PinName nss);
-MAX31865_RTD PT1(MAX31865_RTD::RTD_PT100, D11, D12, D13, A0);
-MAX31865_RTD PT2(MAX31865_RTD::RTD_PT100, D11, D12, D13, A1);
-MAX31865_RTD PT3(MAX31865_RTD::RTD_PT100, D11, D12, D13, A2);
+//GOOD 0, GOOD/ERROR LATCHED 1, ERROR 2
 
-TS_DISCO_F469NI ts;
-TS_StateTypeDef TS_State;
-uint8_t status;
-uint8_t cleared = 0;
-uint8_t prev_nb_touches = 0;
-uint8_t text[30];
-
-int temp_safe=150;                                                              //temperatura di sicurezza per la  quale non è possibile aprire la porta (150)
-int MAXtemp_safe=450;                                                           //temperatura di sicurezza per la  quale non è possibile aprire la porta (450)   
-float setpointHIGH = 450;                                                       //setpoint temperatura high per il clean, temperatura per il cleaning
-float setpointLOW = (setpointHIGH-20);                                          //setpoint temperatura low per il clean
-int clean_time=1800;                                                            //tempo di clean, (1800)
-int tempo_roast =1200;                                                          //tempo di roasting, posso variare con le frecce (1200)
-int temperatura_roast = 200;                                                    //temperatura di roasting, posso variare con le frecce (200)
-int step_clean=0;
-int step_roast=0;
-
+/// FUNZIONI ///////////////////////////////////////////////////////////////////
 
-/// dichiarazione variabili ////////////////////////////////////////////////////
-//per i sensori
-static bool myDataIn[8] = {1,0,1,0,1,0,1,0};
-//myDataIn[0]               tappo caffè chiuso;
-//myDataIn[1]               sensore porta chiusa;
-//myDataIn[2]               finecorsa sarico aperto;
-//myDataIn[3]               finecorsa scarico chiuso;
-//myDataIn[4];               //da dare un nome
-//myDataIn[5];               //da dare un nome
-//myDataIn[6];               //da dare un nome
-//myDataIn[7];               //da dare un nome
-
-//per i relay
-Shifter scheda_8relay;                  //!! pinout defined in library
-Output Bloccoporta;                     //
-Output Giracaffe;                       // 24V, palette agita caffé
-Output Lampadina;                       // Lampadina
-Output VTangenziale;                    // 1
-Output VRadiale;                        // 2
-Output Scarico_caffe;                   // motore scarico caffé
-Output Resistenza1;                     // Heater 1, centrale
-Output Resistenza2;                     // Heater 2, più esterno
-Output Ventola;                         // Cooling, 24V, ventola cassetto caffè
-
-bool Activate_Door;                     //sul SSR per comandare il bloccoporta
-
-extern bool Apro_porta();               //definita più in basso
-bool Chiudo_scarico();                  //definita più in basso
-/// funzioni ///////////////////////////////////////////////////////////////////
-//------------------------------------------------------------------------------
-void object_update()
+void function_PREV_NEXT()
 {
-    //update delle immagini e dello stato delle uscite
-    Lampadina.draw_image    (&_acLampadina_acceso[0], &_acLampadina_spento[0], Lampadina.stato, 230, 20);
-    Resistenza1.draw_image  (&_acResistenza1_acceso[0], &_acResistenza1_spento[0], Resistenza1.stato, 300, 20);
-    Resistenza2.draw_image  (&_acResistenza2_acceso[0], &_acResistenza2_spento[0], Resistenza2.stato, 370, 20);
-    Giracaffe.draw_image    (&_acGiracaffe_acceso[0], &_acGiracaffe_spento[0], Giracaffe.stato, 440, 20);
-    Bloccoporta.draw_image  (&_acPorta_aperto[0], &_acPorta_chiuso[0], Bloccoporta.stato, 230, 90);
-    VTangenziale.draw_image (&_acVTangenziale_acceso[0], &_acVTangenziale_spento[0], VTangenziale.stato, 300, 90);
-    VRadiale.draw_image     (&_acVRadiale_acceso[0], &_acVRadiale_spento[0], VRadiale.stato, 370, 90);
-    Ventola.draw_image      (&_acVentola_acceso[0], &_acVentola_spento[0], Ventola.stato, 440, 90);
-    //update uscita 74HC595
-    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};
-    for (int i=0; i<16; i++) {
-        scheda_8relay.setPin(i,array[i]);
-        wait_us(2);
-        scheda_8relay.write();
-        //sprintf((char*)text, "%d ", array[i]);
-        //lcd.DisplayStringAt(200+20*i, LINE( 7),(uint8_t *)&text, LEFT_MODE);
+    // se premo nella barra inferiore cambio foglio/////////////////////////
+    //if PREV pressed
+    if ( (TS_State.touchDetected) && (TS_State.touchX[0]>=1 && TS_State.touchX[0]<160 && TS_State.touchY[0]>=400)) {
+        actual_sheet = actual_sheet--;
+        if (actual_sheet < 0) {
+            actual_sheet = total_sheet-1;
+        }
+        display_draw_sheet(actual_sheet);
+        wait_ms(120);
+    }
+    //if NEXT pressed
+    if ( (TS_State.touchDetected) && (TS_State.touchX[0]>=641 && TS_State.touchX[0]<800 && TS_State.touchY[0]>=400)) {
+        actual_sheet = actual_sheet++;
+        if (actual_sheet >= total_sheet) {
+            actual_sheet = 0;
+        }
+        display_draw_sheet(actual_sheet);
+        wait_ms(120);
     }
 }
+
 //------------------------------------------------------------------------------
-/// Lampadina
-void Lampadina_acceso()
-{
-    Lampadina.stato=1;
-    object_update();
-}
-void Lampadina_spento()
-{
-    Lampadina.stato=0;
-    object_update();
-}
-//------------------------------------------------------------------------------
-bool setup_griglia()
+void function_check_OT()
 {
-    lcd.Clear(light_sky_blue);
-    lcd.SetBackColor(light_sky_blue);
-    lcd.SetFont(&Font24);
-    lcd.SetTextColor(black);
-    lcd.DisplayStringAt(670, LINE(0), (uint8_t *)"Ver 2.a", LEFT_MODE);
-    Lampadina_acceso();
-    wait(0.1);
-    Lampadina_spento();
-    wait(0.1);
-
-    //update delle immagini e dello stato delle uscite
-    Lampadina.draw_image    (&_acLampadina_acceso[0], &_acLampadina_spento[0], Lampadina.stato, 230, 20);
-    Resistenza1.draw_image  (&_acResistenza1_acceso[0], &_acResistenza1_spento[0], Resistenza1.stato, 300, 20);
-    Resistenza2.draw_image  (&_acResistenza2_acceso[0], &_acResistenza2_spento[0], Resistenza2.stato, 370, 20);
-    Giracaffe.draw_image    (&_acGiracaffe_acceso[0], &_acGiracaffe_spento[0], Giracaffe.stato, 440, 20);
-    Bloccoporta.draw_image  (&_acPorta_aperto[0], &_acPorta_chiuso[0], Bloccoporta.stato, 230, 90);
-    VTangenziale.draw_image (&_acVTangenziale_acceso[0], &_acVTangenziale_spento[0], VTangenziale.stato, 300, 90);
-    VRadiale.draw_image     (&_acVRadiale_acceso[0], &_acVRadiale_spento[0], VRadiale.stato, 370, 90);
-    Ventola.draw_image      (&_acVentola_acceso[0], &_acVentola_spento[0], Ventola.stato, 440, 90);
-
-    //disegno bottoni
-    disegna_pulsanti(STOP);
-    disegna_pulsanti(CLEAN);
-    disegna_pulsanti(ROAST);
-    disegna_pulsanti(PULSANTI);
-
-    lcd.DisplayStringAt(200, LINE( 8),  (uint8_t *)"Time:", LEFT_MODE);
-    lcd.DisplayStringAt(330, LINE(8), (uint8_t *)"'", LEFT_MODE);
-    lcd.DisplayStringAt(385, LINE(8), (uint8_t *)"''", LEFT_MODE);
-    lcd.DisplayStringAt(200, LINE( 10), (uint8_t *)"Temp:", LEFT_MODE);
-    lcd.DrawCircle(355, LINE(10)+3, 4);
-    lcd.DisplayStringAt(360, LINE( 10), (uint8_t *)"C", LEFT_MODE);
-    lcd.DisplayStringAt(620, LINE( 9), (uint8_t *)"T1:", LEFT_MODE);
-    lcd.DisplayStringAt(620, LINE(11), (uint8_t *)"T2:", LEFT_MODE);
-    lcd.DisplayStringAt(620, LINE(13), (uint8_t *)"T3:", LEFT_MODE);
-
-    //per prova, da togliere dopo
-    lcd.SetTextColor(red);
-    lcd.FillRect (620, 20, 70, 70);
-    lcd.SetTextColor(green);
-    lcd.FillRect (620, 100, 70, 70);
-    lcd.SetTextColor(black);
-    lcd.SetBackColor(red);
-    lcd.DisplayStringAt(620, 40, (uint8_t *)"OPEN", LEFT_MODE);
-    lcd.SetBackColor(green);
-    lcd.DisplayStringAt(620, 120, (uint8_t *)"CLOS", LEFT_MODE);
-    lcd.SetBackColor(light_sky_blue);
-    //fino qui
-
-    PT1.configure( true, true, false, false, MAX31865_FAULT_DETECTION_NONE,
-                   true, true, 0x0000, 0x7fff );
-    PT2.configure( true, true, false, false, MAX31865_FAULT_DETECTION_NONE,
-                   true, true, 0x0000, 0x7fff );
-    PT3.configure( true, true, false, false, MAX31865_FAULT_DETECTION_NONE,
-                   true, true, 0x0000, 0x7fff );
-    //Apro_porta();
-    return 0;
-}
-//------------------------------------------------------------------------------
-bool * getData()
-{
-    //define where your pins are
-    DigitalOut latchPin(D7);
-    DigitalOut clockPin(D6);
-    DigitalIn  dataPin(D5);
     float tempoattesa = 20;
     //acquiring values
     latchPin.write(1);
@@ -173,259 +41,144 @@
         wait_us(tempoattesa);
         clockPin.write(0);
         wait_us(tempoattesa);
-        myDataIn[i] = dataPin.read();      //1 if OT open, 0 if OT close
+        //OT[i].state = dataPin.read();                                         //OT open is ok, OT close is error
+        OT[i].state = !dataPin.read();                                          //OT open is error, OT close is OK
+        if (OT[i].state) OT[i].latch_error = 1;
+        if (OT[i].latch_error) (OT[i].state == 1) ? OT[i].state= 2 : OT[i].state = 1;       
         clockPin.write(1);
     }
-    
-    //per prova da togliere dopo
-    for (int i=3; i>=0; i--) {  // D7,D6,.....,D1,D0
-        sprintf((char*)text, "%d", myDataIn[0+i]);
-        lcd.DisplayStringAt(580+20*i,LINE(8), (uint8_t *)&text, LEFT_MODE);
-    }
-    //
-    
-    return myDataIn;
 }
 //------------------------------------------------------------------------------
-/// Resistenza 1
-void Resistenza1_acceso()
+void print_OT_alarmed()
 {
-    Resistenza1.stato=1;
-    object_update();
-}
-void Resistenza1_spento()
-{
-    Resistenza1.stato=0;
-    object_update();
+    lcd.SetFont(&Font24);
+    lcd.SetTextColor(black);
+    lcd.SetBackColor(BackColor);
+    if (OT[0].latch_error) lcd.DisplayStringAt(35, LINE(11), (uint8_t *)"OT 510 LWR TRNS", LEFT_MODE);
+    if (OT[1].latch_error) lcd.DisplayStringAt(35, LINE(12), (uint8_t *)"OT 512 LWR TRNS", LEFT_MODE);
+    if (OT[2].latch_error) lcd.DisplayStringAt(35, LINE(13), (uint8_t *)"OT 51 LWR ZONE 2", LEFT_MODE);
+    if (OT[3].latch_error) lcd.DisplayStringAt(35, LINE(14), (uint8_t *)"OT 52 LWR ZONE 2", LEFT_MODE);
+    if (OT[4].latch_error) lcd.DisplayStringAt(425, LINE(11), (uint8_t *)"OT 54 LWR ZONE 2", LEFT_MODE);
+    if (OT[5].latch_error) lcd.DisplayStringAt(425, LINE(12), (uint8_t *)"OT 55 LWR ZONE 1", LEFT_MODE);
+    if (OT[6].latch_error) lcd.DisplayStringAt(425, LINE(13), (uint8_t *)"OT 57 LWR ZONE 1", LEFT_MODE);
+    if (OT[7].latch_error) lcd.DisplayStringAt(425, LINE(14), (uint8_t *)"OT 58 LWR ZONE 1", LEFT_MODE);   
 }
 //------------------------------------------------------------------------------
-/// Resistenza 2
-void Resistenza2_acceso()
-{
-    Resistenza2.stato=1;
-    object_update();
-}
-void Resistenza2_spento()
-{
-    Resistenza2.stato=0;
-    object_update();
-}
-//------------------------------------------------------------------------------
-void temperature_update()
+void function_check_heaters(int sample)
 {
-    lcd.DisplayStringAt(680, LINE( 9), (uint8_t *)"      ", LEFT_MODE);
-    lcd.DisplayStringAt(680, LINE(11), (uint8_t *)"      ", LEFT_MODE);
-    lcd.DisplayStringAt(680, LINE(13), (uint8_t *)"      ", LEFT_MODE);
-    PT1.read_all( );
-    if (PT1.temperature( )>150)  lcd.SetTextColor(red);
-    else lcd.SetTextColor(black);
-    sprintf((char*)text, "%1.0f", PT1.temperature( ));
-    lcd.DisplayStringAt(680, LINE(9), (uint8_t *)&text, LEFT_MODE);
-    PT2.read_all( );
-    if (PT2.temperature( )>150)  lcd.SetTextColor(red);
-    else lcd.SetTextColor(black);
-    sprintf((char*)text, "%1.0f", PT2.temperature( ));
-    lcd.DisplayStringAt(680, LINE(11), (uint8_t *)&text, LEFT_MODE);
-    PT3.read_all( );
-    if (PT3.temperature( )>150)  lcd.SetTextColor(red);
-    else lcd.SetTextColor(black);
-    sprintf((char*)text, "%1.0f", PT3.temperature( ));
-    lcd.DisplayStringAt(680, LINE(13), (uint8_t *)&text, LEFT_MODE);
-    lcd.SetTextColor(black);
-
-    //per sicurezza la temperatura non può superare la MAX temperaratura di sicurezza (450 gradi)
-    if (PT1.temperature( )>MAXtemp_safe || PT2.temperature( )>MAXtemp_safe) {
-        Resistenza1_spento();
-        Resistenza2_spento();
-        wait(1.0);
+    //signal value
+    Heater[0].average = 0;
+    Heater[1].average = 0;
+    for (int i=0; i<3; i++) {
+        Heater[0].average = Heater[0].average + abs((3.6 * abs(signalHeater1.read()) - 1.8));
+        Heater[1].average = Heater[1].average + abs((3.6 * abs(signalHeater2.read()) - 1.8));
+        wait_us(10);
+    }
+    Heater[0].average = Heater[0].average/3;
+    Heater[1].average = Heater[1].average/3;
+    
+    //if heater is activate .ON_OFF = 1, else = 0
+    for (int i=0; i<MAX_HEATER; i++) {
+        (Heater[i].average >= Heater[i].limit) ? Heater[i].ON_OFF = 1 : Heater[i].ON_OFF = 0;
+        Heater_Samples[i][sample] = Heater[i].ON_OFF;
+    }
+    
+    //define Heater[i].state GOOD = 0, LATCHED = 1, ERROR = 2 investigating ALL samples, OR qualificator among samples
+    for (int i=0; i<MAX_HEATER; i++) {
+        int a_samples = 0;       
+        for (a_samples = 0; a_samples < MAX_Samples; a_samples++) {
+           Heater[i].state = Heater[i].state || Heater_Samples[i][a_samples];
+        }
+        Heater[i].state = 1 - Heater[i].state;
+        a_samples=0;
+        //latch di memoria
+        if (Heater[i].state == 1) Heater[i].latch_error = 1;
+        if (Heater[i].latch_error) (Heater[i].state == 1) ? Heater[i].state= 2 : Heater[i].state = 1; 
     }
 }
 //------------------------------------------------------------------------------
-/// Ventola 12/24 volt
-void Ventola_acceso()
-{
-    Ventola.stato=1;
-    object_update();
-}
-void Ventola_spento()
-{
-    Ventola.stato=0;
-    object_update();
-}
-//------------------------------------------------------------------------------
-/// Ventola Radiale
-void VRadiale_acceso()
+bool check_if_error()
 {
-    VRadiale.stato=1;
-    object_update();
-}
-void VRadiale_spento()
-{
-    VRadiale.stato=0;
-    object_update();
-}
-//------------------------------------------------------------------------------
-/// Ventola Tangenziale
-void VTangenziale_acceso()
-{
-    VTangenziale.stato=1;
-    object_update();
-}
-void VTangenziale_spento()
-{
-    VTangenziale.stato=0;
-    object_update();
+    //return ERRORE 0 GOOD, 1 ERROR
+    if (is_OT_controlled) for (int i=0; i< MAX_OT; i++) ERRORE = ERRORE || OT[i].state;
+    if (is_Heater_controlled) for (int i=0; i< MAX_HEATER; i++) ERRORE = ERRORE || Heater[i].state;
+    if (is_Analog_controlled) for (int i=0; i< MAX_ANALOG; i++) ERRORE = ERRORE || ANALOG[i].state;
+    if (is_Digital_controlled) for (int i=0; i< MAX_DIGITAL; i++) ERRORE = ERRORE || DIGITAL[i].state;
+    return ERRORE;
 }
 //------------------------------------------------------------------------------
-/// Giracaffe
-void Giracaffe_acceso()
+void function_back_to_home_page(int back_home_ms)
 {
-    Giracaffe.stato=1;
-    object_update();
-}
-void Giracaffe_spento()
-{
-    Giracaffe.stato=0;
-    object_update();
+    //funzione che ritorna a visualizzare pagina 0 dopo un tempo espresso in millisecondi
+    (actual_sheet == 0 ) ? initial_time = timer.read_ms() : actual_time = timer.read_ms();
+    if ( actual_time - initial_time > back_home_ms ) {
+        actual_sheet = 0;
+        display_draw_sheet(actual_sheet);
+    }
 }
 //------------------------------------------------------------------------------
-///Apro scarico caffe
-bool Apro_scarico()
+void function_zero_array()
 {
-    getData();
-    while(!myDataIn[2]) {
-        lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"COFFE UNLOAD IS OPENING  ", LEFT_MODE);
-        Scarico_caffe.CW_CCW=1;
-        wait(0.1);
-        Scarico_caffe.ON_OFF=1;
-        temperature_update();
-        object_update();
-        wait(0.012);
-        getData();
-    }
-    Scarico_caffe.ON_OFF=0;
-    object_update();
-    wait(0.012);
-    getData();
-    lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"                             ", LEFT_MODE);
-    wait(0.1);
-    return 0;
-}
-///Chiudo scarico caffe
-bool Chiudo_scarico()
-{
-    getData();
-    while(!myDataIn[3]) {
-        lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"COFFE UNLOAD IS CLOSING  ", LEFT_MODE);
-        Scarico_caffe.CW_CCW=0;
-        wait(0.1);
-        Scarico_caffe.ON_OFF=1;
-        temperature_update();
-        object_update();
-        wait(0.012);
-        getData();
-    }
-    Scarico_caffe.ON_OFF=0;
-    object_update();
-    wait(0.012);
-    getData();
-    lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"                             ", LEFT_MODE);
-    wait(0.1);
-    return 0;
+    int a, b;
+    for (a=0; a<MAX_HEATER; a++) { 
+        for (b=0; b<MAX_Samples; b++) { 
+            Heater_Samples[a][b] = 1;
+        }
+    b=0;
+    }  
 }
 //------------------------------------------------------------------------------
-///Porta
-bool Apro_porta()
-{
-/*
-    int time_door=5;
-    lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"WAIT TO OPEN DOOR        ", LEFT_MODE);
-    while(time_door>0) {
-        sprintf((char*)text, "%5d", time_door);
-        lcd.DisplayStringAt(600,LINE(18), (uint8_t *)&text, LEFT_MODE);
-        time_door--;
-        temperature_update();
-        wait(1);
-    }
-    //attivazione del relay per aprire la porta
-    for (int i=0; i<2; i++) {
-        Activate_Door=1;
-        object_update();
-        //wait_us(20);
-        wait(0.02);
-        Activate_Door=0;
-        object_update();
-        wait(4);
-        //wait_us(20);
-    }
-    ///
-    lcd.DisplayStringAt(600, LINE(18), (uint8_t *)"     ", LEFT_MODE);
-    lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"DOOR IS OPEN             ", LEFT_MODE);
-    wait(1.0);
-    lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"                         ", LEFT_MODE);
-    Bloccoporta.stato=0;
-    object_update();
-*/
-    return 0;
-}
-bool Chiudo_porta()
+void function_check_analog()
 {
-/*
-    int time_door=5;
-    bool stato_porta;
-    getData();
-    lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"WAIT TO CLOSE DOOR       ", LEFT_MODE);
-    while(time_door>0) {
-        sprintf((char*)text, "%5d", time_door);
-        lcd.DisplayStringAt(600,LINE(18), (uint8_t *)&text, LEFT_MODE);
-        time_door--;
-        temperature_update();
-        wait(1);
-    }
-    lcd.DisplayStringAt(600, LINE(18), (uint8_t *)"     ", LEFT_MODE);
-//attivazione del relay per chiudere la porta
-    if (!myDataIn[1]) {
-        for (int i=0; i<1; i++) {
-            Activate_Door=1;
-            object_update();
-            wait(0.02);
-            //wait_us(20);
-            Activate_Door=0;
-            object_update();
-            wait(0.05);
-            //wait_us(20);
+    for (int n=0; n< MAX_ANALOG; n++)
+        {            
+            ANALOG[n].average = 0;
+            selectInput4051(n);
+            wait_us(10);
+            for (int a=0; a<3; a++)
+                {
+                ANALOG[n].average = ANALOG[n].average + analog_value.read();
+                wait_us(5);
+                }
+            ANALOG[n].average = (ANALOG[n].average/3 - ANALOG[n].offset);
+        if (ANALOG[n].average < ANALOG[n].limit) ANALOG[n].latch_error = 1;
+        if (ANALOG[n].latch_error) (ANALOG[n].average < ANALOG[n].limit) ? ANALOG[n].state= 2 : ANALOG[n].state = 1; 
         }
-        ///
-        Bloccoporta.stato=1;
-        object_update();
-        lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"DOOR IS CLOSED           ", LEFT_MODE);
-        stato_porta=0;
-        wait(2.0);
-    } else {
-        lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"CLOSE THE  DOOR PLEASE   ", LEFT_MODE);
-        stato_porta=1;
-    }
-    lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"                         ", LEFT_MODE);  
-    return stato_porta;
-    */
-    return 0;
 }
 //------------------------------------------------------------------------------
-///Tappo caffè
-bool tappo_caffe()
+void function_print_analog()
+{
+    lcd.SetTextColor(black);
+    for (int n=0; n< MAX_ANALOG; n++)
+        {  
+            sprintf((char*)text, "%2.2f", ANALOG[n].average);
+            lcd.DisplayStringAt(180,LINE(2+n), (uint8_t *)&text, LEFT_MODE);
+            (ANALOG[n].average > ANALOG[n].limit) ? lcd.SetTextColor(forestgreen) : lcd.SetTextColor(red);
+            lcd.FillRect(260, LINE(2+n), 15, 15);
+            lcd.SetTextColor(black);
+        }
+    lcd.SetTextColor(black);
+}
+//------------------------------------------------------------------------------
+void function_check_digital()
 {
-    bool stato_tappo_caffe;
-    getData();
-    if (myDataIn[0]) {
-        lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"COFFE COVER IS CLOSED    ", LEFT_MODE);
-        stato_tappo_caffe=0;
-    } else {
-        lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"CLOSE COFFE COVER PLEASE ", LEFT_MODE);
-        stato_tappo_caffe=1;
-    }
-    wait(1.0);
-    lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"                         ", LEFT_MODE);
-    return stato_tappo_caffe;
+    DIGITAL[0].average = digital_signal_1.read();
+    //DIGITAL[1].average = digital_signal_2.read();
+    for (int n=0; n< MAX_DIGITAL; n++)
+        {            
+            if (DIGITAL[n].average == 0) DIGITAL[n].latch_error = 1;
+            if (DIGITAL[n].latch_error) (DIGITAL[n].average == 0) ? DIGITAL[n].state= 2 : DIGITAL[n].state = 1; 
+        }
 }
-//End of Functions//
+//------------------------------------------------------------------------------
+void function_print_digital()
+{
+    for (int n=0; n< MAX_DIGITAL; n++)
+        {  
+            (DIGITAL[n].average > DIGITAL[n].limit) ? lcd.SetTextColor(forestgreen) : lcd.SetTextColor(red);
+            lcd.FillRect(220, LINE(11+n), 15, 15);
+        }
+    lcd.SetTextColor(black);
+}
 #endif
+