Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

Errore nel compilare lo sketch

Progetti, interfacciamento, discussioni varie su questa piattaforma.

Moderatori: Foto UtenteWALTERmwp, Foto Utentexyz

0
voti

[1] Errore nel compilare lo sketch

Messaggioda Foto Utentepapa10 » 21 lug 2017, 17:59

Ciao a tutti ho bisogno del vostro aiuto,perche' nonostante tutto il mio impegno non sono riuscito a risolverlo.L'errore che mi da' expected ' ,' 'registro' - registra -else if Grazie a tutti-
Codice: Seleziona tutto
/* --------------------------------------------------------------------------
Imposto l'orario su un modulo RTC (con interfaccia seriale I2C) tramite il
keypad (# per settare la data e * per settare l'orario) e poi lo mostro su
un display LCD 20x4 con interfaccia seriale I2C "YwRobot Arduino LCM1602
IIC V1". Il pin SDA di I2C è connesso alla pin analogico A4 mentre SCL e'
connesso alla pin analogico A5
-------------------------------------------------------------------------- */
#include "Wire.h"  // E' richiesta da I2CIO.cpp

// *************************************************************
// IMPOSTAZIONE PER L'OROLOGIO
// *************************************************************
#include "RTClib.h"
RTC_DS1307 RTC;

// *************************************************************
// IMPOSTAZIONE PER IL KEYPAD
// *************************************************************
#include "Keypad.h"

const byte ROWS = 4; //4 righe
const byte COLS = 3; //3 colonne
char keys[ROWS][COLS] =
{
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; // Pin di arduino connessi ai pin 1,2,3 e 4 delle righe del keypad
byte colPins[COLS] = {4, 3, 2};    // Pin di arduino connessi ai pin 5,6,7 delle righe del keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

// *************************************************************
// IMPOSTAZIONI PER IL DISPLAY LCD
// *************************************************************
#include "LiquidCrystal_I2C.h" // Libreria LCD I2C
// Imposta i pin usati sul chip I2C per le connessioni
// con il display LCD: addr, en, rw ,rs ,d4 ,d5 ,d6 ,d7 ,bl ,blpol
// ed inoltre pone l'indirizzo del display a 0x27
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

// -------------------------------------------------------------
// PROGRAMMA VERO E PROPRIO
// -------------------------------------------------------------
// Variabili globali necessarie al nostro progetto.
#define StringaVuota "                    ";
String cifre="";
boolean AttivaModificaData;
boolean AttivaModificaOra;

void ScriviRiga3e4(String Frase3, String Frase4)
{
   if (Frase3!="")
   {
      lcd.setCursor(0, 2);  // 1° colonna - 3° riga
      lcd.print(Frase3);
   }
   if (Frase4!="")
   {
      lcd.setCursor(0, 3);  // 1° colonna - 4° riga
      lcd.print(Frase4);
   }
}

void Pulisci3e4Riga()
{
    String Vuota="                    ";
    ScriviRiga3e4(Vuota,Vuota);
}

void Pulisci4Riga()
{
    String Vuota="                    ";
    ScriviRiga3e4("",Vuota);
}

void MessaggioAvviso(String Frase1, String Frase2)
{
    String Frase3="...:: "+Frase1+" ::...";
    String Frase4=">> "+Frase2;
    ScriviRiga3e4(Frase3,Frase4);
}

void printLCD_DateTime(DateTime now)
{
  char buffer[25]={'\0'};
  sprintf(buffer, "DATA: %02u/%02u/%u",now.day(),now.month(),now.year());
  lcd.setCursor(0, 0);  // 1° colonna - 1° riga
  lcd.print(buffer);
  sprintf(buffer, "ORA:  %02u:%02u:%02u",now.hour(), now.minute(), now.second());
  lcd.setCursor(0, 1);  // 1° colonna - 2° riga
  lcd.print(buffer);
}

boolean EUnaDataCorretta(uint8_t dd, uint8_t mm, uint16_t yy)
{
  uint8_t GGMese[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
  if ((mm<1) || (mm>12)) return false; // non e' un mese!
  if (yy % 4 == 0) GGMese[1]=29; // Bisestile
  if (dd<1 || dd>GGMese[mm-1]) return false;
  return true;
}

boolean EUnOraCorretta(uint8_t hh, uint8_t mm, uint8_t ss)
{
  if ( (hh>23) || (mm>59) || (ss>59) ) return false;
  return true;
}


void AnnullaSet()
{
   AttivaModificaData=false;
   AttivaModificaOra=false;
   cifre="";
}

void Registra()
{
   DateTime DataOraRTC = RTC.now();
   DateTime DataOraNuova;
   uint8_t dd, mm, hh, ss;
   uint16_t yy;
   if (cifre.length()!=6) return; // ignoro # o * prima delle 6 cifre
   if (AttivaModificaOra==true)
   {
       hh=(uint8_t)cifre.substring(0,2).toInt();
       mm=(uint8_t)cifre.substring(2,4).toInt();
       ss=(uint8_t)cifre.substring(4,6).toInt();
       if ( EUnOraCorretta(hh,mm,ss) )
       {
         DataOraNuova=DateTime(DataOraRTC.year(),DataOraRTC.month(),
                               DataOraRTC.day(),hh,mm,ss);
         RTC.adjust(DataOraNuova);
         MessaggioAvviso("SET ORA ","Orario settato!");
       }
       else
         MessaggioAvviso("SET ORA ",cifre.substring(0,2)+":"
                                   +cifre.substring(2,4)+":"
                                   +cifre.substring(4,6)+" ERRATA!");
   }
   else if (AttivaModificaData==true)
   {
       dd=(uint8_t)cifre.substring(0,2).toInt();
       mm=(uint8_t)cifre.substring(2,4).toInt();
       yy=(uint16_t)(2000+cifre.substring(4,6).toInt());
       if ( EUnaDataCorretta(dd,mm,yy) )
       {
           DataOraNuova=DateTime(yy,mm,dd,DataOraRTC.hour(),
                                 DataOraRTC.minute(),DataOraRTC.second());
           RTC.adjust(DataOraNuova);
           MessaggioAvviso("SET DATA","Data settata!");
       }
       else
         MessaggioAvviso("SET DATA",cifre.substring(0,2)+"/"
                                   +cifre.substring(2,4)+"/"
                                   +cifre.substring(4,6)+" ERRATA!");
   }
   AnnullaSet();
}

void StampaConSeparatore(String cifr)
{
    int i;
    char sep=(AttivaModificaData) ? '/' : ':';
    Pulisci4Riga();
    lcd.setCursor(0,3);
    lcd.print(">> IN: ");
    for (i=0; i registro
           Registra();
         else if (AttivaModificaOra)
         {
           AnnullaSet();  // Azzero l'impostazione della data
           Pulisci3e4Riga();
         }
         else
         {
           AttivaModificaData=true;
           cifre="";
           MessaggioAvviso("SET DATA","IN: GG:MM:AA");
         }
      }
      else if (key=='*') // Imposta orario
      {
         if (AttivaModificaOra) // 2° * => registro
           Registra();
         else if (AttivaModificaData)
         {
           AnnullaSet();  // Azzero l'impostazione dell'ora
           Pulisci3e4Riga();
         }
         else
         {
           AttivaModificaOra=true;
           cifre="";
           MessaggioAvviso("SET ORA ","IN: HH:MM:SS");
         }
      }
      else if (AttivaModificaOra || AttivaModificaData)
      {
        if (cifre.length()<6) // non vado oltre le 6 cifre
        {
            cifre=cifre+String(key);
            StampaConSeparatore(cifre);
        }
      }
    }
    delay(20);
}
Avatar utente
Foto Utentepapa10
71 1 3 4
Frequentatore
Frequentatore
 
Messaggi: 248
Iscritto il: 20 ott 2011, 17:11

0
voti

[2] Re: Errore nel compilare lo sketch

Messaggioda Foto Utentexyz » 21 lug 2017, 18:13

Quando segnali un errore devi riportare l'errore completo, compresa l'indicazione della riga.

Questa riga non ha senso in C/C++:

Codice: Seleziona tutto
  for (i=0; i registro
Avatar utente
Foto Utentexyz
6.864 2 4 6
G.Master EY
G.Master EY
 
Messaggi: 1778
Iscritto il: 5 dic 2009, 18:37
Località: Italy Turin

0
voti

[3] Re: Errore nel compilare lo sketch

Messaggioda Foto Utentepapa10 » 21 lug 2017, 18:23

ma funziona adesso
Avatar utente
Foto Utentepapa10
71 1 3 4
Frequentatore
Frequentatore
 
Messaggi: 248
Iscritto il: 20 ott 2011, 17:11

0
voti

[4] Re: Errore nel compilare lo sketch

Messaggioda Foto Utentefranx » 26 lug 2017, 9:56

l'identificatore registro (variabile ?) non risulta precedentemente dichiarato o visibile.
Avatar utente
Foto Utentefranx
465 3 10
Frequentatore
Frequentatore
 
Messaggi: 199
Iscritto il: 28 feb 2010, 17:43


Torna a Arduino

Chi c’è in linea

Visitano il forum: Nessuno e 2 ospiti