/*
 * Task 4 - LCD display
 * 
 * Example of writing characters to a Hitachi 44780 LCD display.
 * 
 * Derived from the
 * Arduino LCD Tutorial
 *
 * which I found on www.makerguides.com/character-lcd-arduino-tutorial/
 * 
 * but also seems to be on www.HowToMechatronics.com
 * I don't know which (if either) is the original.
 * 
 */

// External LiquidCrystal library that makes this much easier
#include <LiquidCrystal.h> 

// Here we instantiate a specific instance of the LiquidCrystal class
// The parameters specify the Arduino pins for the various LCD pins
// The order of the parameters is (rs, enable, d4, d5, d6, d7)
// Putting this declaration here creates the lcd variable in global scope  
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);   

void setup() { 
// Initialize the LCD interface. All that is needed is the screen dimensions.
 lcd.begin(16,2); 
}

void loop() {
  // Clear the screen and set the cursor to (0, 0) (column, row) in the upper-left corner
  lcd.clear(); // Clears the LCD screen 
  delay(3000); // Dramatic pause

  // Print something to the first first row of the display (it is that easy!)
  lcd.print("Arduino"); 
  delay(3000); // 3 seconds delay 

  // Move the cursor to the bottom row (row 1) third column (column 2)
  // The next print command will start the text here
  lcd.setCursor(2,1);  
  lcd.print("LCD Tutorial"); 
  delay(3000); 
  
 //lcd.clear(); // Clears the display and returns the cursor to (0,0)
 lcd.blink(); //Displays the blinking LCD cursor 
 lcd.setCursor(15,1); 
 delay(3000); 

 // Print one character at a time from a string
 // Strings are automatically terminated with the null character (value: 0)
 lcd.autoscroll();
 char hello[] = "Hello World!! ";
 for (int i=0; hello[i] != '\0'; i++) {
  lcd.print(hello[i]);
  delay(500);
 }
 lcd.noAutoscroll();

 // Turn off cursor
 lcd.noBlink();
 lcd.noCursor();
 delay(4000);

}