Pages: [1]   Go Down
Author Topic: LCD in Sleep mode showing zzz's  (Read 722 times)
0 Members and 1 Guest are viewing this topic.
South East USA
Offline Offline
God Member
*****
Karma: 4
Posts: 636
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Trying to figure this out, I got so tired of zzz's remaining on the screen from previous print calls, I just did this:
I'd be much obliged if someone could shorten this code up a bit!
Code:
void Hibernate(){
  /*
  Sleep mode, shows sleeping zzz's, rising and falling across the screen
  waits for keypress to awaken
  */
  srlcd.clear();  //clear screen and set cursor at home
  while(key == NO_KEY){
    srlcd.clear();
    srlcd.print("Z");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZZZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZZZZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZZZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("ZZ");
    key = keypad.getKey();
    delay(100);
    srlcd.clear();
    srlcd.print("Z");
    key = keypad.getKey();
    delay(100);
   
    delay(2000);  //breathe pause
   }
  Restart_Standby(); //reset display message for hibernate exit 
}
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 26
Posts: 4119
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You should not have to rewrite existing Zs to the LCD once they have been written.  So for the first half of your pattern all you have to do on each iteration is: (1) don't clear the LCD and (2) just print another 'Z'. 

For the second half you want to have the LCD address counter decrement instead of increment.  This is done with the LCD 'Entry Mode Set command. Then just print a 'SPACE' on each iteration.

An easier display to implement, that does not require changing the Entry Mode would have the row of Zs shrink from the left side rather than from the right side.  For this you would just reset the cursor and start printing spaces.


Original sequence:
Z
ZZ
ZZZ
ZZZZ
ZZZZZ
ZZZZZZ
ZZZZZZZ
ZZZZZZZZ
ZZZZZZZZZ
ZZZZZZZZZZ
ZZZZZZZZZZZ
ZZZZZZZZZZZZ
ZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZ
ZZZZZZZZZZZZ
ZZZZZZZZZZZ
ZZZZZZZZZZ
ZZZZZZZZZ
ZZZZZZZZ
ZZZZZZZ
ZZZZZZ
ZZZZZ
ZZZZ
ZZZ
ZZ
Z



Revised sequence:

Z
ZZ
ZZZ
ZZZZ
ZZZZZ
ZZZZZZ
ZZZZZZZ
ZZZZZZZZ
ZZZZZZZZZ
ZZZZZZZZZZ
ZZZZZZZZZZZ
ZZZZZZZZZZZZ
ZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZ
ZZZZZZZZZZZZZZZZ
 ZZZZZZZZZZZZZZZ
  ZZZZZZZZZZZZZZ
   ZZZZZZZZZZZZZ
    ZZZZZZZZZZZZ
     ZZZZZZZZZZZ
      ZZZZZZZZZZ
       ZZZZZZZZZ
        ZZZZZZZZ
         ZZZZZZZ
          ZZZZZZ
           ZZZZZ
            ZZZZ
             ZZZ
              ZZ
               Z


Don
Logged

Hamme, Belgium
Offline Offline
Sr. Member
****
Karma: 4
Posts: 386
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You should use something like this (it's like setting up an animation)

Code:
void sleep(){
  fill();
  empty();
}

void fill(){
  for (char i=0;i<17;i++){
    srlcd.print("Z");
    key = keypad.getKey();
    delay(100);
  }
}

void empty(){
  for (char i=0;i<17;i++){
    srlcd.print(" ");
    key = keypad.getKey();
    delay(100);
  }
}

if you want the empty space go from right to left, you'll have to set rightToLeft() (if you're using LiquidCrystal.h)
Logged


Pages: [1]   Go Up
Jump to: