// This sketch is based on instructions found here: http://blog.jongallant.com/2015/10/particle-photon-lcd-setup/
// The next few lines are to state what we’re using and the general things we need to have happen
#include "application.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(D0, D1, D2, D3, D4, D5);
SYSTEM_MODE(AUTOMATIC);
// The LCD will show this when there’s no quote or when the quote is loading so the screen is never blank
String content = "Waiting for the quote of the day";
int strLength;
// This gives the dimensions of the LCD
void setup() {
lcd.begin(16, 2);
// Display Quote is the function being used by particle
Particle.function("Display Quote", displayQuote);
}
// This loop will allow the quote to scroll and fit on the LCD so it can be read, and will repeat the scrolling automatically. The actually scrolling code is further down
void loop() {
// This says that when the string length is greater than 16 characters, the LCD should use the scrolling function
strLength = content.length();
if (strLength > 16) {
scrollText();
}
//This part of the code allows the LCD to keep itself from scrolling when the quote is less than 16 characters
else {
lcd.home();
lcd.print(content);
}
}
boolean displayQuote (String subject) {
content = subject;
return true;
}
// This is the breakdown of the code allowing the quote to scroll on the LCD
void scrollText() {
String onScreen;
for (int i = 0; i < strLength - 15; i++) {
lcd.home();
onScreen = content.substring(i, i + 16);
lcd.home();
lcd.print(onScreen);
delay(750);
}
}
Comments
Please log in or sign up to comment.