1

My code means that when i press a button it displays a word, but by default words are already there and i need to get rid of those default words.

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7,8,9,10,11,12);

int buttonApin = 4;

void setup() {
 pinMode(buttonApin, INPUT_PULLUP);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Mission Control ");
}

void loop() 
{
  if (digitalRead(buttonApin) == LOW)
  {
    lcd.setCursor(0, 1);
    lcd.print("Test");
  } 


  lcd.setCursor(0, 1);

lcd.print("launch in ");  
lcd.print(millis()/1000);
3

The HD44780 controller has a 80 bytes (characters) memory, in order to support up to 2x40 character displays. Since you use a 2x16 display, there is an empty space in the memory you can use on your benefit. It's like having two desktops, you are able to show one or the other.

Refer to LCD Addressing for a visualization of the the memory locations and detailed explanation.

enter image description here

Anything you write in locations setCursor(16, 0) to setCursor(39, 0) and setCursor(16, 1) to setCursor(39, 1) will not be visible until you scroll to the left. Consequently you can have some text already written in the hidden area and then alternate the shown text just by scrolling left and right.

Here is an example

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7,8,9,10,11,12);

int buttonApin = 4;

void setup() {
   // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);  
}

void loop() 
{
  if (digitalRead(buttonApin) == LOW)
  {
    // write text to the visible area
    lcd.setCursor(0, 0);
    lcd.print("showing 0,0-15,0");
    lcd.setCursor(0, 1);
    lcd.print("showing 1,0-15,1");

    // write text to the hidden area
    lcd.setCursor(16, 0);
    lcd.print("now  16,0-31,0");
    lcd.setCursor(16, 1);
    lcd.print("now  16,1-31,1");

    while (1) {  // scroll to the left and back to show different text without writing a single character
    delay(2000);
    for(uint8_t i=0;i<16;i++) lcd.scrollDisplayLeft();
    delay(2000);
    for(uint8_t i=0;i<16;i++) lcd.scrollDisplayRight();
    }

  } 

}

The code changes the visible text just by scrolling

3

Either clear the display first, or print enough spaces after to overwrite the existing text.

  • Yes that would work, but i would like the original (defualt) text to reappear after the button has been pressed. – Stratmoss Aug 6 '14 at 16:43
  • 2
    @Stratmoss if it works, then why not do that? You're going to have to re-print the text to the LCD as it doesn't have any memory... – Anonymous Penguin Aug 6 '14 at 16:59
  • @AnnonomusPenguin Are you sure about the memory? – alexan_e Aug 6 '14 at 22:31
  • 1
    It has a tiny bit of memory, but unless you can handle page switching (one of many optimization techniques mostly lost to history) it won't help. – Ignacio Vazquez-Abrams Aug 6 '14 at 22:35
  • @Stratmoss I'd estimate another write would take less than a 100 bytes (you have 32,000 bytes). If you want to make sure, when you click "verify," it tells you how big it is at the bottom. – Anonymous Penguin Aug 6 '14 at 22:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.