Bluetooth Display - Teil 6 - AZ-Delivery

Benvenuti nella sesta e ultima parte della nostra serie Bluetooth Display.

Anche in questa parte ho escomano qualcosa di bello come supplemento alle funzioni precedenti. Nella parte di oggi, ci concentreremo sulla gestione dell'energia e della batteria dell'unità. Questo è un supplemento all'ultima parte, dove abbiamo usato il nostro display come un cartellone pubblicitario al mercato delle pulci. Raramente ci sono spine al mercato delle pulci, quindi dobbiamo operare il nostro display con una banca di potenza. Ma cosa succede se stiamo esaurendo l'energia, o vogliamo sapere se la tensione di alimentazione è ancora 5 volt? Questo è meglio farlo utilizzando uno degli ingressi analogici per misurare la tensione della batteria e visualizzando la tensione di funzionamento direttamente in volt sul nostro display.

Inoltre, una funzione di risparmio energetico sarebbe utile, che possiamo operare con i controlli (pulsanti) costruiti in precedenza. Inoltre, il nostro display ora riceve finalmente una funzione di debug, che ci aiuta a trovare errori a livello tecnico e porta un sollievo con le estensioni del codice.

Ma affinché il nostro display sia in grado di rilevare la tensione della pelle di alimentazione, è necessario fare un'altra piccola espansione hardware. Questa estensione consiste nel collegamento della porta analogica 5 con la tensione operativa VDD. Sotto la connessione costituita da un ponte di filo è mostrato nello schema e contrassegnato da una freccia rossa.

Anche in questa parte facciamo un'estensione o la regolazione del codice sorgente firmware e quindi caricare il seguente codice per l'Arduino:

 

#include <Spi.H>
#include <Filo.H>
#include <SoftwareSerialseriale.H>
#include <Eeprom.H>
#include <LiquidoCristallo.H>
#include <Avr/Dormire.H>

# define MaxInputBufferSize 20 massimo 255 caratteri per adattarsi a vlcdr
# define Dimensioni e-promSize 990

# define rLcdChr 20
# define LcdRows (informazioni in base ai colori in 4
# define Intervallo 1000
# define BackgroundLight 5 LED retroilluminazione porta 5
# define VoltageSensingPin 5 // 
# define SwitchPin (SwitchPin) 2 Pulsanti di selezione dei messaggi della porta 12
# define DelayTOPWROFF 500 
# define MinOPVoltage 3.4

EEprom Memory CellAddresses per la configurazione
# define EEFadeSecondi  993
# define EEAdvertsecdelay 994
# define EEAdvertMsg 995
# define EEPINA 996
# define EPINC 997
# define EEPINDD 998 

SoftwareSerialseriale mySerial(7, 6); RX, TX

LiquidCrystal(rs, enable, d4, d5, d6, d7) 
LiquidoCristallo Lcd(8, 13, 12, 11, 10, 9);


Variabili
Byte DisplayBankContent (Contenuto Della banca) = 0; 

Gestione dell'input seriale
Char TBuffer (TBuffer);
Char Cbuffer (Cbuffer)[MaxInputBufferSize+1];       Buffer di input codice USB
Stringa Buffer = "";                      Buffer di input stringa USB
Int Valore;                                USB Nummeric Input Buffer
Byte Conteggio cconteggio = 0;                          Numero ricevuto Chars
Byte Inptype (Inptype) = 0;
Boolean StrInput = False;
Boolean NumeroIngresso = False;
Boolean DataInput (Input dati) = False;
Boolean Input enter = False;
Byte MenueSelezione = 0;

Controllo pulsante
Boolean Stato di commutazione = Vero;
Boolean SwitchstateBuffer (Server switch) = Vero;
Byte SelectedMsg = 0;

Fornire informazioni di debug tramite l'interfaccia seriale
Boolean DebugMode (Modalità Debug) = False;
Boolean Modalità Echo = Vero;

Eeprom
Int eeaddress (indirizzo eeaddress);                 Puntatore indirizzo EEPROM
Byte EEPromBanche = 0;          Utilizzato per il calcolo delle banche EEPROM
Controllo SerMnue
Byte MnuState = 0;            Profondità massima del menu 255 icl Sub
Byte Banca selezionata =0;

Orologio in tempo reale 
Lungo previousMillis = 0;       memorizzerà l'ultima volta è stato misurato
Lungo previousMillisB = 0;       memorizzerà l'ultima volta è stato misurato

Gestione del display
Boolean DisplayLock (DisplayLock) = False;
Boolean Impronta diretta = False;
Byte Stampa direttaROW = 0;
Byte Stampa direttaLinea = 0;

Boolean AggiornaVisualizzazione = False;
Byte FRMControllo = 0; Usato fpr operazioni di scrittura per eeprom in modo da salvare i cicli host
Monitoraggio della batteria
Galleggiante Tensione;
Boolean PowersaveMode (Modalità Powersave) = False;

PWM Lichtsteuerung 

byte Luminosità corrente = 0;
byte Luminosità di destinazione = 0;
byte FadeSecondi = 0; Standard n. 3

Visualizzazione automatica di Werbungszwecke

Boolean Pubblicità = False;
byte AdvertMsg = 1; Minimo 1
byte Ritardo advertsec = 0; Standard : 6
byte Contatore pubblicità = 0;


Vuoto Installazione()    {    EEPromBanche = Dimensioni e-promSize / ((rLcdChr) * LcdRows (informazioni in base ai colori in);   Lcd.Iniziare(rLcdChr, LcdRows (informazioni in base ai colori in);   Lcd.Chiaro();   Lcd.Setcursor(0, 0);   Lcd.Stampare(Bluetooth");   Lcd.Setcursor(0, 1);   Lcd.Stampare("Visualizzazione");   mySerial.Iniziare(9600);   PinMode (Modalità pin)(SwitchPin (SwitchPin),INPUT_PULLUP); Taster Auswahl Testo aus EEprom   PinMode (Modalità pin)(BackgroundLight,Output); Displaybeleuchtung / Visualizza an /AUS   digitalWrite (Scrittura digitale)(BackgroundLight,Basso);   leggere Config   FadeSecondi = Eeprom.Leggere(EEFadeSecondi);    Ritardo advertsec =Eeprom.Leggere(EEAdvertsecdelay);   AdvertMsg =Eeprom.Leggere(EEAdvertMsg);   Luminosità corrente = 0;   Luminosità di destinazione = 0;   Lcd.Setcursor(0, 4);   Se (DisplayLock (DisplayLock)) {  Lcd.Stampare(" Gesperrt di sistema"); }   Ulteriori routine di installazione / inizializzazione   Lcd.Setcursor(0, 0);   Luminosità di destinazione = 255;   mySerial.sciacquone();
}

// ###################################################################################################### //

Vuoto Ciclo() 
{
SerialcommandProcessore();
runrealTimeClock();
Processore di visualizzazione();
SwitchProcessore();
Ciclo principale finale
}

// ###################################################################################################### //


Vuoto Intestazione di testo(byte rowm)
{    mySerial.println("Testo per banca" + Stringa( Banca selezionata) + " RIGA " + Stringa (rowm) + ":");   }

Vuoto SerialcommandProcessore()
{
Int Un;
Inptype (Inptype) = 0;
Inptype (Inptype) = SerInputHandler();
0 cheine R'ckgabe 
1 Nummer 
2 Stringa 
3 Dati

Se ((Inptype (Inptype) > 0) & (!Impronta diretta))                {    Se (PowersaveMode (Modalità Powersave)) {    TogglePowerSave (Clic di Comando)(False);      }      MenueSelezione = 0;    Se (Pubblicità)    {      Lcd.Chiaro();      Pubblicità = False;      mySerial.Stampare(F("Pubblicità"));      mySerial.println(F("FUORI".));      }    Se ((MnuState < 2) && (Inptype (Inptype) == 2)) {Buffer.ToUpperCase (Caso in taupper)(); } Per facilitare l'immissione dei comandi      Se ((Buffer == "DEBUG") && (MnuState == 0) && (Inptype (Inptype) == 2))   { MenueSelezione = 1;}    Se ((Buffer == "ECHO")&& (MnuState == 0) && (Inptype (Inptype) == 2))       { MenueSelezione = 2;}    Se ((Buffer == "S") && (MnuState == 0) && (Inptype (Inptype) == 2))       { MenueSelezione = 3;}    Cancellazione di TUTTI i contenuti EEprom    Se ((Buffer == "E") && (MnuState == 0) && (Inptype (Inptype) == 2))       { MenueSelezione = 4;}    Se ((Buffer == "SÌ") && (MnuState == 1)&& (Inptype (Inptype) == 2))      { MenueSelezione = 5;}    Se ((Buffer != "SÌ") && (MnuState == 1) && (Inptype (Inptype) == 2))     { MenueSelezione = 6;}    Modifica contenuto selezionato    Se ((Buffer == "W") && (MnuState == 0) && (Inptype (Inptype) == 2))       { MenueSelezione = 7;}    Se ((MnuState == 2) && (Valore  < EEPromBanche) && (Inptype (Inptype) == 1)) { MenueSelezione = 8;}    Se (MnuState == 3)                                               { MenueSelezione = 9;}    Se (MnuState == 4)                                               { MenueSelezione = 10;}    Visualizza contenuto selezionato    Se ((Buffer == "P") && (MnuState == 0) && (Inptype (Inptype) == 2))       { MenueSelezione = 11;}    Se ((MnuState == 5) && (Inptype (Inptype) == 1))                           { MenueSelezione = 12;}    Se ((Buffer == "R") && (MnuState == 0) && (Inptype (Inptype) == 2))       { MenueSelezione = 13;}    Se ((MnuState == 6) && (Inptype (Inptype) == 1))                           { MenueSelezione = 14;}    Se ((Buffer == "D" (D)) && (MnuState == 0) && (Inptype (Inptype) == 2))       { MenueSelezione = 15;}    Se ((Buffer == "z") && (MnuState == 0) && (Inptype (Inptype) == 2))       { MenueSelezione = 16;}    Se ((Buffer == "B") && (MnuState == 0) && (Inptype (Inptype) == 2))       { MenueSelezione = 17;}    Se ((MnuState == 7) && (Inptype (Inptype) == 1))                           { MenueSelezione = 18;}    Se ((Buffer == "DISSOLVEnza") && (MnuState == 0) && (Inptype (Inptype) == 2))     { MenueSelezione = 19;}    Se (MnuState == 9)                                               { MenueSelezione = 20;}    Se (MnuState == 10)                                              { MenueSelezione = 21;}    Se ((Buffer == "A") && (MnuState == 0) && (Inptype (Inptype) == 2))       { MenueSelezione = 22;}    Se ((Buffer == "ADVERT") && (MnuState == 0) && (Inptype (Inptype) == 2))  { MenueSelezione = 23;}    Se (MnuState == 11)                                              { MenueSelezione = 24;}    Se (MnuState == 12)                                              { MenueSelezione = 25;}    Se ((Buffer == "ADSEC") && (MnuState == 0) && (Inptype (Inptype) == 2))   { MenueSelezione = 26;}    Se (MnuState == 13)                                              { MenueSelezione = 27;}    Se ((Buffer == "ADMSG") && (MnuState == 0) && (Inptype (Inptype) == 2))   { MenueSelezione = 28;}    Se (MnuState == 14)                                              { MenueSelezione = 29;}      Interruttore (MenueSelezione)      {        Caso 1:            {          mySerial.Stampare("Debug");          DebugMode (Modalità Debug) = !DebugMode (Modalità Debug);          Se (DebugMode (Modalità Debug)) {          mySerial.println(F("ON".));          Modalità Echo = False;           } Altro           {              mySerial.println(F("FUORI".));             Modalità Echo = Vero;           }          mySerial.println("");          mySerial.sciacquone();          Valore = 0;          MnuState = 0;          Buffer = "";          Pausa;        }        Caso 2:            {           mySerial.Stampare(F("Echo"));           Modalità Echo = !Modalità Echo;           Se (Modalità Echo) {             mySerial.println(F("ON".));             DebugMode (Modalità Debug) = False;             } Altro             {              mySerial.println(F("FUORI".));             }           mySerial.println(F(""));           mySerial.sciacquone();           Valore = 0;           MnuState = 0;           Buffer = "";           Pausa;        }        Caso 3:            {          mySerial.println(F("Leggi contenuto EEEPROM:" ));          mySerial.sciacquone();          Per (Int Un = 0; Un < EEPromBanche; Un++)            {              mySerial.println("Banca di memoria EEPROM: " + Stringa(Un) );              mySerial.sciacquone();              Per (Int B = 1; B <= LcdRows (informazioni in base ai colori in;B++)                 {                   mySerial.Stampare("Riga" + Stringa(B) +": ");                   mySerial.sciacquone();                   Per (Int C = 0; C <rLcdChr; C++)                       {                         eeaddress (indirizzo eeaddress) = 0;                           eeaddress (indirizzo eeaddress) = (Un * (rLcdChr)* LcdRows (informazioni in base ai colori in) + ((rLcdChr) * B) + C;                         Valore = Eeprom.Leggere(eeaddress (indirizzo eeaddress));                         mySerial.Stampare(Char(Valore));                         mySerial.sciacquone();                                              }                   mySerial.println(F(" "));                   mySerial.sciacquone();                 }                                           }                    Buffer = "";          mySerial.println(F("Non sono più disponibili banche EEPROM."));          mySerial.sciacquone();          Pausa;        }        Caso 4:            {          Valore = 0;          mySerial.Stampare("Cancellare EEPROM");          mySerial.println(F("SÌ/NO:"));          mySerial.sciacquone();          MnuState = 1;          Buffer = "";          Pausa;        }        Caso 5:            {         Valore = 0;       mySerial.Stampare(F("Cancellare EEPROM"));         mySerial.println(F("Stand by."));         mySerial.sciacquone();         Per (Int Un = 0; Un < EEPromBanche; Un++)           {             Banca di memoria a             mySerial.println("Banca Chiara: " + Stringa(Un));             Per (Int B = 1; B <= LcdRows (informazioni in base ai colori in;B++)               {                Per (Int C = 0; C <rLcdChr; C++)                   {                     eeaddress (indirizzo eeaddress) = 0;                       eeaddress (indirizzo eeaddress) = (Un * (rLcdChr)* LcdRows (informazioni in base ai colori in) + ((rLcdChr ) * B) + C;                     FRMControllo = Eeprom.Leggere(eeaddress (indirizzo eeaddress));                     Se (FRMControllo > 0)                     {                     Eeprom.Scrivere(eeaddress (indirizzo eeaddress),00); Formatierung                     mySerial.Stampare(".");                     Valore++;                     Ritardo(30);                     mySerial.sciacquone();                     }                   }               }             mySerial.println("");             mySerial.sciacquone();           }         mySerial.println("");                             mySerial.println("Finito".+ Stringa(Valore) + " Byte cancellati");         mySerial.println("");         mySerial.sciacquone();         Buffer = "";         MnuState = 0;         Pausa;        }        Caso 6:        {         Valore = 0;         Buffer = "";         MnuState = 0;         mySerial.println(F("Interruzione OP".));         mySerial.sciacquone();         Pausa;          }        Caso 7:        {        mySerial.println("Numero di banca EEPPROM (0-" + Stringa(EEPromBanche-1) + "):");        mySerial.sciacquone();        MnuState = 2;        Valore = 0;        Buffer = "";        Pausa;        }        Caso 8:        {        Banca selezionata = Valore;        Intestazione di testo(1);               MnuState = 3;        Buffer = "";        Valore = 0;        Pausa;        }        Caso 9:        {        Scrittura(Banca selezionata,1);             Intestazione di testo(2);        Valore = 0;        MnuState = 4;        Buffer = "";        Pausa;        }        Caso 10:        {        Scrittura(Banca selezionata,2);         Valore = 0;        MnuState = 0;        Buffer = "";        Intestazione di testo(3);        mySerial.sciacquone();        Valore = 0;        MnuState = 9;        Buffer = "";        Pausa;        }                Caso 11:        {        Valore = 0;      mySerial.println("Numero di banca EEPPROM (0-" + Stringa(EEPromBanche-1) + "):");        MnuState = 5;        Buffer = "";        mySerial.sciacquone();        Pausa;        }         Caso 12:        {        SelectedMsg = Valore;        DisplayBank(Valore);          Pausa;        }        Caso 13:        {        Valore = 0;        mySerial.println("Numero di banca EEPPROM (0-" + Stringa(EEPromBanche-1) + "):");        MnuState = 6;        Buffer = "";        mySerial.sciacquone();        Pausa;        }        Caso 14:        {         Un = Valore;         Se ( Un < EEPromBanche)         {         mySerial.println("Banca della memoria: " + Stringa(Un) );         mySerial.sciacquone();         Per (Int B = 1; B <= LcdRows (informazioni in base ai colori in;B++)           {             mySerial.Stampare("Riga" + Stringa(B) +": ");             mySerial.sciacquone();             Per (Int C = 0; C <rLcdChr; C++)               {                 eeaddress (indirizzo eeaddress) = 0;                   eeaddress (indirizzo eeaddress) = (Un * (rLcdChr)* LcdRows (informazioni in base ai colori in) + ((rLcdChr) * B) + C;                 Valore = Eeprom.Leggere(eeaddress (indirizzo eeaddress));                 mySerial.Stampare(Char(Valore));                 mySerial.sciacquone();                                      }             mySerial.println(" ");             mySerial.sciacquone();           }         } Altro            {            mySerial.println(F("Valore non compreso nell'intervallo."));               }                     Valore = 0;              Buffer = "";         MnuState = 0;         Pausa;        }        Caso 15:        {        PPrint diretto da visualizzare        Impronta diretta = Vero;        mySerial.println ("Directprint ON.");        Se (Impronta diretta)        {        Stampa direttaROW = 0;        Stampa direttaLinea = 0;        Lcd.Chiaro();        Lcd.Cursore();        Lcd.Lampeggiare();        }        Valore = 0;             Buffer = "";        MnuState = 0;        Pausa;         }        Caso 16:        {        Valore = 0;             Buffer = "";        MnuState = 0;        Pausa;         }        Caso 17:        {        mySerial.println(F("Luminosità del display: (max 255)"));        MnuState = 7;        Valore = 0;        Buffer = "";        Pausa;        }        Caso 18:        {        Se ((Valore < 256))          {            Luminosità di destinazione = Valore;            mySerial.println("Luminosità: " + Stringa (Luminosità di destinazione) + "Imposta");                  } Altro           {            mySerial.println(F("Valore non compreso nell'intervallo."));                }        MnuState = 0;              Valore = 0;        Buffer = "";        Pausa;        }        Caso 19:        {       mySerial.println(F("Ritardo dissolvenza: (max 255 sec)"));        MnuState = 12;        Valore = 0;        Buffer = "";        Pausa;        }        Caso 20:        {        Scrittura(Banca selezionata,3);         Valore = 0;        MnuState = 0;        Buffer = "";        Intestazione di testo(4);        mySerial.sciacquone();        Valore = 0;        MnuState = 10;        Buffer = "";        Pausa;        }        Caso 21:        {        Scrittura(Banca selezionata,4);         Valore = 0;        MnuState = 0;        Buffer = "";        Pausa;        }        Caso 22:        {        MnuState = 0;        Buffer = "";        mySerial.println(F("Entra nel NUOVO PIN BT"));        mySerial.sciacquone();        MnuState = 11;        Pausa;        }        Caso 23:        {        Pubblicità  = !Pubblicità;             mySerial.Stampare(F("Pubblicità"));        Se (Pubblicità)          {          mySerial.println(F("ON".));         } Altro  { mySerial.println(F("FUORI".)); }        mySerial.sciacquone();        Valore = 0;        MnuState = 0;        Buffer = "";        Pausa;        }                Caso 24:        {         Se ((Valore > 1000) & (Valore < 10000))        {        mySerial.Stampare("NUOVO PIN"+ Buffer);              Ritardo(1000);        mySerial.sciacquone();               Ritardo(1000);         mySerial.println("AT: PIN"+ Buffer);        Ritardo(3000);        mySerial.sciacquone();              } Altro        {        Valore = 0;        Buffer = "";        mySerial.println(F("Valore non compreso nell'intervallo."));         }                 Valore = 0;        MnuState = 0;        Buffer = "";        Pausa;        }        Caso 25:        {         Se ((Valore > 0) & (Valore < 251))        {                FadeSecondi = Valore;        Eeprom.Scrivere(EEFadeSecondi, FadeSecondi);        mySerial.println("Valore" + Stringa (Valore) + " insieme.");        } Altro        {        Valore = 0;        Buffer = "";        mySerial.println(F("Valore non compreso nell'intervallo."));        }                 Valore = 0;        MnuState = 0;        Buffer = "";        Pausa;        }        Caso 26:        {       mySerial.println(F("ADverDelay: (max 255 sec)"));        MnuState = 13;        Valore = 0;        Buffer = "";        Pausa;        }        Caso 27:        {         Se ((Valore > 0) & (Valore < 256))        {                Ritardo advertsec = Valore;        Eeprom.Scrivere(EEAdvertsecdelay,Ritardo advertsec);      mySerial.println("Valore" + Stringa (Valore) + " insieme.");        } Altro        {        Valore = 0;        Buffer = "";        mySerial.println(F("Valore non compreso nell'intervallo."));         }                 Valore = 0;        MnuState = 0;        Buffer = "";        Pausa;        }        Caso 28:        {       mySerial.println("ADMsgs: (max" + Stringa (EEPromBanche) + ")");       MnuState = 14;        Valore = 0;        Buffer = "";        Pausa;        }        Caso 29:        {         Se ((Valore > 0) & (Valore < EEPromBanche +1))        {                AdvertMsg = Valore;        Eeprom.Scrivere(EEAdvertMsg,AdvertMsg);      mySerial.println("Valore" + Stringa (Valore) + " insieme.");        } Altro        {        Valore = 0;        Buffer = "";        mySerial.println(F("Valore non compreso nell'intervallo."));         }                 Valore = 0;        MnuState = 0;        Buffer = "";        Pausa;        }        Predefinito:        {          Se (DisplayLock (DisplayLock))             {              Lcd.Chiaro();             DisplayLock (DisplayLock) = False;            }          mySerial.println(F("-------Smart Bluetooth Display 1.1------"));          mySerial.println(F("S - Leggi TUTTE le banche EEPROM"));          mySerial.println(F("E - Cancella TUTTE le banche EEPROM"));          mySerial.println(F("W - Scrivi banca EEPROM"));          mySerial.println(F("R - Leggi sel. EEPROM Bank"));          mySerial.println(F("P - Stampa Banca EEPROM sul display"));          mySerial.println(F("----------------------------------------"));          mySerial.println(F("D - Stampa diretta"));          mySerial.println("B - Visualizza il valore attuale di Brighness: " + Stringa (Luminosità corrente));          mySerial.println(F("----------------------------------------"));          mySerial.println(F("A - PIN di accesso Bluetooth"));          mySerial.println(F("Altro: ADVERT,ADSEC,ADMSG,FADE,ECHO"));           mySerial.println(F("----------------------------------------"));          mySerial.println(F("Digitare Cmd e premere Invio"));          mySerial.sciacquone();          Se (DebugMode (Modalità Debug))            {                  mySerial.println("Debug: CmdProc End Typ: " + Stringa(Inptype (Inptype)) + " Inhalt: " +Buffer);            mySerial.sciacquone();           }          MnuState = 0;          Valore = 0;          Buffer = "";        }     }    } Eingabe erkannt
}

Vuoto Scrittura(byte FBank,byte Riga F)
{
byte Scrivicounter;

Scrivicounter = 0; 
 mySerial.Stampare("Salvataggio");        Per (Int C = 0; C <rLcdChr; C++)           {            eeaddress (indirizzo eeaddress) = 0;              eeaddress (indirizzo eeaddress) = (FBank * (rLcdChr)* LcdRows (informazioni in base ai colori in) + ((rLcdChr) * Riga F) + C;              Valore = Eeprom.Leggere(eeaddress (indirizzo eeaddress));            Se (Buffer[C] != Valore)            {            Eeprom.Scrivere(eeaddress (indirizzo eeaddress),Buffer[C]);            mySerial.Stampare(".");            Scrivicounter++;              }           }        mySerial.println(" " + Stringa (Scrivicounter) + "Byte scritti.");     }

Vuoto ClearCBuffer (Buffer Di ClearC) ()
{
 Per (byte Un= 0; MaxInputBufferSize -1;Un++)   Cbuffer (Cbuffer)[Un] = 0;   }    byte SerInputHandler()

{
byte Risultato = 0;
Int C;
Int D;
Int Un;
Int B;
Risultato = 0;
Se (VerificaforserialE())     {       Se ((NumeroIngresso) E Non (DataInput (Input dati))E Non (StrInput))     Solo numeri        {        Buffer = "";        Valore = 0;        StrInput = False;        NumeroIngresso = False;        DataInput (Input dati) = False;        Input enter = False;         Un = 0;        B = 0;        C = 0;        D = 0;        Buffer = Cbuffer (Cbuffer); AUCH wird ! in SBUFFER sbernommen, cade bentigt.        Se (Conteggio cconteggio == 1) { Valore  = Cbuffer (Cbuffer)[0]- 48 ; }        Se (Conteggio cconteggio == 2) {           Un = Cbuffer (Cbuffer)[0] - 48 ;           Un = Un * 10;          B = Cbuffer (Cbuffer)[1] - 48 ;          Valore = Un + B;          }        Se (Conteggio cconteggio == 3) {           Un = Cbuffer (Cbuffer)[0] - 48 ;           Un = Un * 100;          B = Cbuffer (Cbuffer)[1] - 48 ;          B = B * 10;          C = Cbuffer (Cbuffer)[2] - 48 ;          Valore = Un + B + C;          }        Se (Conteggio cconteggio == 4) {           Un = Cbuffer (Cbuffer)[0] - 48 ;           Un = Un * 1000;          B = Cbuffer (Cbuffer)[1] - 48 ;          B = B * 100;          C = Cbuffer (Cbuffer)[2] - 48 ;          C = C * 10;          D = Cbuffer (Cbuffer)[3] - 48 ;          Valore = Un + B + C + D;          }        Se (Conteggio cconteggio >= 5)            {            Buffer = "";            Valore = 0;            Buffer = Cbuffer (Cbuffer);            ClearCBuffer (Buffer Di ClearC);            Risultato = 2;             } Altro           {            ClearCBuffer (Buffer Di ClearC);            Se (DebugMode (Modalità Debug))              {             mySerial.println("Debug: Numero: "+Stringa(Valore));              mySerial.sciacquone();            }            Conteggio cconteggio = 0;            Risultato = 1;                                                Numero Codice restituito            NumeroIngresso = False;            StrInput = False;            DataInput (Input dati) = False;            Input enter = False;             Conteggio cconteggio = 0;            Ritorno Risultato;            }        }      Se ((StrInput) E Non (DataInput (Input dati)))                          Solo input stringa        {         Buffer = "";         Buffer = Cbuffer (Cbuffer);          Se (DebugMode (Modalità Debug))              {                mySerial.println("Debug: Stringa: "+Buffer);               mySerial.sciacquone();             }        Valore = 0;        StrInput = False;        NumeroIngresso = False;        DataInput (Input dati) = False;        Input enter = False;         Conteggio cconteggio = 0;        ClearCBuffer (Buffer Di ClearC);        Risultato = 2;                                                 Numero Codice restituito        }       Se (DataInput (Input dati)) {        Buffer = "";        Buffer = Cbuffer (Cbuffer);        Valore = 0;        StrInput = False;        NumeroIngresso = False;        DataInput (Input dati) = False;        Input enter = False;         Se (DebugMode (Modalità Debug))           {            mySerial.println("Debug: dati: "+Buffer);             mySerial.sciacquone();          }        Conteggio cconteggio = 0;        ClearCBuffer (Buffer Di ClearC);        Risultato = 3;                                               Numero Codice restituito        }        Se ((Input enter) E Non (StrInput) E Non (NumeroIngresso) E Non (DataInput (Input dati)))        {        Buffer = "";        Valore = 0;        Se (DebugMode (Modalità Debug))           {            mySerial.println(F("Debug: Inserisci solo premuto"));             mySerial.sciacquone();          }        Conteggio cconteggio = 0;        ClearCBuffer (Buffer Di ClearC);        Risultato = 4;                                               Numero Codice restituito        }             NumeroIngresso = False;    StrInput = False;    DataInput (Input dati) = False;    Input enter = False;     Conteggio cconteggio = 0;    Ritorno Risultato;     } 
Ritorno Risultato;          Fine controlloforSerialEvent
}

Eingabebuffer
Boolean VerificaforserialE()
{   Mentre (mySerial.Disponibile()) {      ottenere il nuovo byte:      TBuffer (TBuffer) = mySerial.Leggere();       Se (TBuffer (TBuffer) > 9 && TBuffer (TBuffer) < 14)        {         Cbuffer (Cbuffer)[Conteggio cconteggio] = 0;         TBuffer (TBuffer) =0;         Se (Modalità Echo)           {            mySerial.Stampare(Char(13));            mySerial.sciacquone();          }            Se (Impronta diretta)           {           mySerial.println("");           Stampa direttaLinea = 0;           Stampa direttaROW = Stampa direttaROW + 1;           Se ( Stampa direttaROW > 3)            {                     Impronta diretta = False;                    Lcd.noCursor (Cursore)();                    Lcd.noBlink();                    Buffer = "";                    Valore = 0;                                 } Altro            {           Lcd.Cursore();           Lcd.Lampeggiare();           Lcd.Setcursor(0,Stampa direttaROW);           }           }                Se (DebugMode (Modalità Debug))            {                 mySerial.println("Debug: immettere ricevuto. Lunghezza: " + Stringa(Conteggio cconteggio));           mySerial.sciacquone();           }          Input enter = Vero;           Ritorno Vero;      } Altro Se (TBuffer (TBuffer) > 47 && TBuffer (TBuffer) <58 )       {        Se ( Conteggio cconteggio < MaxInputBufferSize)           {             Cbuffer (Cbuffer)[Conteggio cconteggio] = TBuffer (TBuffer);               Conteggio cconteggio++;             Se ((Impronta diretta))               {                  Lcd.Stampare(Char(TBuffer (TBuffer)));                  Stampa direttaLinea = Stampa direttaLinea + 1;                  Se ( Conteggio cconteggio > MaxInputBufferSize -1)                   {                    Lcd.noCursor (Cursore)();                    Lcd.noBlink();                    } Altro {                    Lcd.Cursore();                    Lcd.Lampeggiare();                    }                                 }                      Se (Modalità Echo) {              mySerial.Stampare(Char(TBuffer (TBuffer)));              mySerial.sciacquone();             }            } Altro {mySerial.Stampare("#"); }            Se (DebugMode (Modalità Debug)) {        mySerial.println(F("Debug: numero su seriale ricevuto"));        mySerial.sciacquone();       }       Numero Ingresso rilevato       NumeroIngresso = Vero;       }        Altro Se (TBuffer (TBuffer) > 64 && TBuffer (TBuffer) < 123 )       {        Se ( Conteggio cconteggio < MaxInputBufferSize)           {             Cbuffer (Cbuffer)[Conteggio cconteggio] = TBuffer (TBuffer);               Conteggio cconteggio++;             Se ((Impronta diretta))               {                  Lcd.Stampare(Char(TBuffer (TBuffer)));                                 Stampa direttaLinea = Stampa direttaLinea + 1;                  Se ( Conteggio cconteggio > MaxInputBufferSize -1)                   {                    Lcd.noCursor (Cursore)();                    Lcd.noBlink();                    } Altro {                    Lcd.Cursore();                    Lcd.Lampeggiare();                    }                       }                Se (Modalità Echo) {              mySerial.Stampare(Char(TBuffer (TBuffer)));              mySerial.sciacquone();             }            } Altro {mySerial.Stampare("#"); }          Se (DebugMode (Modalità Debug)) { mySerial.println(F("Debug: Char su Serial ricevuto"));       mySerial.sciacquone(); }         Rilevato input carattere carattere       StrInput = Vero;      }     Altro Se ( (TBuffer (TBuffer) == 127 )  |  (TBuffer (TBuffer) == 8 ) )          {                                                Se ( Stampa direttaLinea > 0 )                  {                  Stampa direttaLinea = Stampa direttaLinea - 1;                  Lcd.Setcursor(Stampa direttaLinea, Stampa direttaROW);                   Lcd.Stampare(" ");                  Lcd.Setcursor(Stampa direttaLinea, Stampa direttaROW);                   }                                                       Se (( Stampa direttaLinea == 0 ) & ( Stampa direttaROW > 0 ))                  {                  Stampa direttaROW = Stampa direttaROW - 1;                   Stampa direttaLinea = rLcdChr -1;                  Lcd.Setcursor(Stampa direttaLinea, Stampa direttaROW);                   }           Se ( Conteggio cconteggio > 0)           {             Conteggio cconteggio--;             Cbuffer (Cbuffer)[Conteggio cconteggio] = 0;             Se ((Impronta diretta))               {                  Se ( Conteggio cconteggio > MaxInputBufferSize -1)                   {                    Lcd.noCursor (Cursore)();                    Lcd.noBlink();                    } Altro {                    Lcd.Cursore();                    Lcd.Lampeggiare();                    }                       }                                          Se (Modalità Echo) {              mySerial.Stampare("-");              mySerial.sciacquone();             }            }        }          Altro         {                Se ( Conteggio cconteggio < MaxInputBufferSize)           {             Cbuffer (Cbuffer)[Conteggio cconteggio] = TBuffer (TBuffer);               Conteggio cconteggio++;              Se ((Impronta diretta))               {                  Stampa direttaLinea = Stampa direttaLinea + 1;                  Se (TBuffer (TBuffer) < 128) {Lcd.Stampare(Char(TBuffer (TBuffer))); } Altro  {Lcd.Stampare(Stringa(TBuffer (TBuffer))); }                  Se ( Conteggio cconteggio > MaxInputBufferSize -1)                   {                    Lcd.noCursor (Cursore)();                    Lcd.noBlink();                    } Altro {                    Lcd.Cursore();                    Lcd.Lampeggiare();                    }                       }                Se (Modalità Echo) {              mySerial.Stampare(Char(TBuffer (TBuffer)));              mySerial.sciacquone();             }            } Altro {mySerial.Stampare("#"); }              Se (DebugMode (Modalità Debug))           {             mySerial.println(F("Debug: dati su seriale ricevuti"));            mySerial.sciacquone();          }        Immissione dati rilevata       DataInput (Input dati) = Vero;       }      Ritorno False;      }     Ritorno False;   }    Vuoto Processore di visualizzazione()  Bei Blauem Display wird auf Scrollfunktion verzichtet, da das nur "schmiert"
{
Se (AggiornaVisualizzazione)   {     Lcd.Chiaro();     AggiornaVisualizzazione = False;        Per (Int B = 1; B <= LcdRows (informazioni in base ai colori in;B++)                 {                   Lcd.Setcursor(0, B -1);                   Se (!Pubblicità) {mySerial.Stampare("Riga" + Stringa(B) +": "); }                   Per (Int C = 0; C <rLcdChr; C++)                       {                         eeaddress (indirizzo eeaddress) = 0;                           eeaddress (indirizzo eeaddress) = (DisplayBankContent (Contenuto Della banca) * (rLcdChr)* LcdRows (informazioni in base ai colori in) + ((rLcdChr) * B) + C;                         Valore = 0;                         Valore = Eeprom.Leggere(eeaddress (indirizzo eeaddress));                         Se (Valore > 31) Sonderzeichen nicht anzeigen                         {                          Se (!Pubblicità) { mySerial.Stampare(Char(Valore)); } Altro { Ritardo(100);}                          Lcd.Stampare(Char(Valore));                          } Altro                         { Lcd.Stampare(Char(32)); }                                              }                    Se (!Pubblicità) { mySerial.println();  }                 }                               }         }

Vuoto runrealTimeClock()    BASE TEMPORALE
{   Orologio in tempo reale & Conto alla rovescia
 lungo precedenteMillis - 0;       memorizzerà l'ultima volta è stato misurato
 byte SecDivider - 0;
Unsigned Lungo currentMillis = millis();

Int ValoreStepValue = 0;
PWM Display Steuerung
 ValoreStepValue = 4 * FadeSecondi;   Se(currentMillis - previousMillis > ValoreStepValue)   {      previousMillis = currentMillis;              Se (Luminosità corrente < Luminosità di destinazione   )   {   Luminosità corrente = Luminosità corrente + 1;   analogicoScrittura (BackgroundLight,Luminosità corrente);        } Altro Se (Luminosità corrente > Luminosità di destinazione)    {   Luminosità corrente = Luminosità corrente - 1;   analogicoScrittura (BackgroundLight,Luminosità corrente);     }    }   Se(currentMillis - previousMillisB > 1000)    {   sekundentakt     previousMillisB = currentMillis;      BattMonitoring();
Pubblicità     Se (Pubblicità)     {      Se (Contatore pubblicità >  Ritardo advertsec)       {       Contatore pubblicità = 0;         DisplayBankContent (Contenuto Della banca) = DisplayBankContent (Contenuto Della banca) + 1;       Se (DisplayBankContent (Contenuto Della banca) > AdvertMsg - 1) { DisplayBankContent (Contenuto Della banca) = 0; }       AggiornaVisualizzazione = Vero;       } Altro { Contatore pubblicità = Contatore pubblicità +1; }            }       }   }

Vuoto DisplayBank ( byte cobank)
 {        Se (cobank  < EEPromBanche )        {        AggiornaVisualizzazione = Vero;   Inializzare l'output di visualizzazione        DisplayBankContent (Contenuto Della banca) = cobank;        mySerial.println("Banca" + Stringa(cobank) + " viene visualizzato su LCD");                 MnuState = 0;        Buffer = "";        Valore =0;        mySerial.sciacquone();        } Altro               {                 mySerial.println(F("Banca non disponibile."));                 Valore = 0;                 MnuState = 0;                 Buffer = "";                 mySerial.sciacquone();               }        }

Vuoto TogglePowerSave (Clic di Comando)(Boolean Stato)
{
mySerial.Stampare("Modalità Powersave"); 
 Se (!Stato)     {     PowersaveMode (Modalità Powersave) = False;    Luminosità di destinazione = 255;    mySerial.println(F("OFF"));    } Altro    {    PowersaveMode (Modalità Powersave) = Vero;    Luminosità di destinazione = 0;    mySerial.println(F("ON"));      }
}    Vuoto SwitchProcessore()
{
Stato di commutazione = digitalRead (Lettura digitale)(SwitchPin (SwitchPin));
Se ((!Stato di commutazione) && (SwitchstateBuffer (Server switch)) && (Non DisplayLock (DisplayLock)))Abfrage Schalter   {    SwitchstateBuffer (Server switch) = False;    Pubblicità = False;    Impronta diretta = False;    Lcd.noCursor (Cursore)();    Lcd.noBlink();    Se (PowersaveMode (Modalità Powersave))     {    TogglePowerSave (Clic di Comando)(False);     } Altro    {    SelectedMsg = SelectedMsg + 1;      Se (SelectedMsg >  EEPromBanche - 1 )        {       SelectedMsg = 0;       }     Lcd.Chiaro();     Lcd.Setcursor(0,0);     Lcd.Stampare("Banca: " + Stringa(SelectedMsg) + "Selezionato");     Lcd.Setcursor(0,2);          Lcd.Stampare("Sistema VDD: " + Stringa(Tensione) + "V");     Ritardo(10);     Valore = DelayTOPWROFF;          Mentre (digitalRead (Lettura digitale)(SwitchPin (SwitchPin)) == 0)     {      Ritardo(1);      Se (Valore > 0) {Valore = Valore - 1;};      Se (Valore == 0 &&  Non PowersaveMode (Modalità Powersave))      {      TogglePowerSave (Clic di Comando)(Vero);      if (SelectedMsg - 0 ) - SelectedMsg - EEPromBanks;      Lcd.Setcursor(0,3);      Lcd.Stampare("Spegni OK");         }      Lcd.Setcursor(0,3);      Se (Valore > 0) {Lcd.Stampare("Spegnimento: " + Stringa(Valore /100)+ " sec ");};      }     DisplayBank(SelectedMsg);    }      }    Se (Stato di commutazione)      {       SwitchstateBuffer (Server switch) = Vero;     ritardo(10);     }    }

Vuoto Powerdown ()  Attiva/disattiva accensioni, se si raggiunge Tensione critica.
{
 Lcd.Chiaro();
 Lcd.Setcursor(0,0);
 Lcd.Stampare("Avviso batteria LOW");
 Lcd.Setcursor(0,2);
 Lcd.Stampare("Carica batteria.");
 Impronta diretta = False;
 Pubblicità = False;
 Ritardo(5000);
 TogglePowerSave (Clic di Comando)(Vero);
}

Vuoto BattMonitoring()

{   Int Stato batteria;   Stato batteria = analogicOLettura(VoltageSensingPin);    leggere il pin di input
 Aggiungere una media dei valori misurati   Tensione = Stato batteria * (0.00489);
 Se (Tensione <= MinOPVoltage) 
{ 
Powerdown(); 
}

}

 

La banca di testo attualmente selezionata viene ora visualizzata non solo come prima, ma anche la tensione operativa corrente. (nell'immagine sotto 4.97 volt) e un contatore che conta il conto alla rovescia a partire da 5 e si spegne il sistema quando viene raggiunto 0. Il sistema viene arrestato anche quando viene firmata la tensione operativa minima specificata nel codice sorgente. Attualmente, il display viene svuotato e la retroilluminazione spenta, ma rimane fondamentalmente fornito di tensione. Se si desidera, è possibile passare il display tramite transistor effetto campo anche privo di tensione. Tuttavia, per semplicità, mi sono astenuto dal farlo.

Nel menu stesso, ora gins il comando "nascosto" "debug" che attiva e disattiva la modalità di debug semplicemente digitando il comando. La seguente schermata dal telefono cellulare APP "BlueTerm" che consiglio vivamente per questo progetto, è possibile visualizzare gli output aggiuntivi (contrassegnati con il prefisso "Debug:" ) che vengono emessi quando la modalità è attivata. Nella schermata è possibile visualizzare l'output di debug di tutti i caratteri ricevuti tramite interfaccia seriale. (Qui debug)
Dopo aver ricevuto il comando di debug, la modalità di debug viene disattivata e riconosciuta con "Debug OFF".

Vi auguro molto divertimento ricostruzione. Ci vediamo presto per il tuo prossimo blog e progetto. Spero che vi sia divertito tanto a ricostruire come ho fatto io durante lo sviluppo.

DisplaysFür arduinoProjekte für fortgeschrittene

Lascia un commento

Tutti i commenti vengono moderati prima della pubblicazione