~josealberto4444/arduino-quiz

5397023899f1c5f0d8ddb5524211f524149aab89 — josealberto4444 2 years ago 38b69ee
Add message scrolling functions
1 files changed, 33 insertions(+), 4 deletions(-)

M questionsAndAnswers/questionsAndAnswers.ino
M questionsAndAnswers/questionsAndAnswers.ino => questionsAndAnswers/questionsAndAnswers.ino +33 -4
@@ 1,9 1,38 @@
void setup() {
  // put your setup code here, to run once:
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);

void scrollHMessage(String message) {
  // Show a message scrolling horizontally along the first line of the screen
  String spaceFilling = "                ";
  message = spaceFilling + message + spaceFilling;
  for (int i = 0; i < message.length() - 14; i+=2) {
    lcd.setCursor(0, 0);
    lcd.print(message.substring(i, i+16));
    delay(400);
  }
}

void loop() {
  // put your main code here, to run repeatedly:
void scrollVMessage(String message) {
  // Show a message scrolling vertically along the screen
  String spaceFilling = "                ";
  message = spaceFilling + message + spaceFilling;
  for (int i = 0; i < message.length() - 16; i+=16) {
    lcd.setCursor(0, 0);
    lcd.print(message.substring(i, i+16));
    lcd.setCursor(0, 1);
    lcd.print(message.substring(i+16, i+32));
    delay(1000);
  }
}

void setup() {
  lcd.init();
  lcd.backlight();
}

void loop() {
  scrollVMessage("This is quite a long message to show in this tiny screen. =P");
  scrollHMessage("This is quite a long message to show in this tiny screen. =P");
}