// This example shows various featues of the library for LCD with 16 chars and 2 lines. #include #include #include LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line display int show = -1; // 2 custom characters byte dotOff[] = { 0b00000, 0b01110, 0b10001, 0b10001, 0b10001, 0b01110, 0b00000, 0b00000 }; byte dotOn[] = { 0b00000, 0b01110, 0b11111, 0b11111, 0b11111, 0b01110, 0b00000, 0b00000 }; void showStatus(uint8_t data_){ Serial.print(" status==");Serial.print(data_);Serial.println(""); } void setup() { int error; Serial.begin(115200); Serial.println("==Start LCD=="); // wait on Serial to be available on Leonardo while (!Serial) ; Serial.println("Probing for PCF8574 on address 0x27..."); // See http://playground.arduino.cc/Main/I2cScanner how to test for a I2C device. PORTE |= (1 << PORTE1); Wire1.begin(); Wire1.setClock(10000); Serial.println(" after Wire.begin() ..."); Serial.flush(); PORTE |= (1 << PORTE1); Wire1.beginTransmission(0x27); Serial.println(" after beginTransmission() ..."); Serial.flush(); error = Wire1.endTransmission(); Serial.print(" End Transmission, Error-code is: "); Serial.println(error); Serial.flush(); if (error == 0) { Serial.println(" LCD found."); Serial.flush(); show = 0; lcd.begin(16, 2, Wire1); // initialize the lcd lcd.createChar(1, dotOff); lcd.createChar(2, dotOn); } else { Serial.println(" LCD not found."); Serial.flush(); } // if } // setup() void loop() { if (show == 0) { showStatus(show); lcd.setBacklight(255); lcd.home(); lcd.clear(); lcd.print("Hello LCD"); delay(1000); lcd.setBacklight(0); delay(400); lcd.setBacklight(255); } else if (show == 1) { showStatus(show); lcd.clear(); lcd.print("Cursor On"); lcd.cursor(); } else if (show == 2) { showStatus(show); lcd.clear(); lcd.print("Cursor Blink"); lcd.blink(); } else if (show == 3) { showStatus(show); lcd.clear(); lcd.print("Cursor OFF"); lcd.noBlink(); lcd.noCursor(); } else if (show == 4) { showStatus(show); lcd.clear(); lcd.print("Display Off"); lcd.noDisplay(); } else if (show == 5) { showStatus(show); lcd.clear(); lcd.print("Display On"); lcd.display(); } else if (show == 7) { showStatus(show); lcd.clear(); lcd.setCursor(0, 0); lcd.print("*** first line."); lcd.setCursor(0, 1); lcd.print("*** second line."); } else if (show == 8) { showStatus(show); lcd.scrollDisplayLeft(); } else if (show == 9) { showStatus(show); lcd.scrollDisplayLeft(); } else if (show == 10) { showStatus(show); lcd.scrollDisplayLeft(); } else if (show == 11) { showStatus(show); lcd.scrollDisplayRight(); } else if (show == 12) { showStatus(show); lcd.clear(); lcd.print("write-"); } else if (show == 13) { showStatus(show); lcd.clear(); lcd.print("custom 1:<\01>"); lcd.setCursor(0, 1); lcd.print("custom 2:<\02>"); } else { showStatus(show); lcd.print(show - 13); } // if delay(1400); show = (show + 1) % 16; } // loop()