Just wanted to post this for anyone else who is looking for a simple countdown timer to use with this lcd. Should be easily modifiable for use with others or to suit your specific needs.
I wanted to post this after looking all over for a simple countdown timer library or sketch and not finding one.
This is using the Adafruit library for PCD8544 GitHub - adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library: Arduino driver for PC8544, most commonly found in small Nokia 5110's
you also need the GFX library mentioned on that page GitHub - adafruit/Adafruit-GFX-Library: Adafruit GFX graphics core Arduino library, this is the 'core' class that all our other graphics libraries derive from
Here's the sketch
/*********************************************************************
This is an example sketch for a countdown timer using Nokia 5110 LCD
and adafruit library for the display
RWSDev.net
*********************************************************************/
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
// pin 7 - SCE
// pin 6 - RST
// pin 5 - D/C
// pin 4 - DN
// pin 3 - SCLK
// set timer position on lcd
int xPos = 16;
int yPos = 16;
int hours = 0;
int minutes = 0;
int seconds = 5;
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);
void setup() {
display.begin();
display.clearDisplay(); // clears the screen and buffer
display.display();
}
void loop() {
while (hours > 0 || minutes > 0 || seconds >= 0) {
display.clearDisplay(); // clears the screen and buffer
display.setContrast(30);
display.setCursor(xPos, yPos);
(hours < 10) ?display.print("0"):NULL;
display.print(hours);
display.print(":");
(minutes < 10) ?display.print("0"):NULL;
display.print(minutes);
display.print(":");
(seconds < 10) ?display.print("0"):NULL;
display.print(seconds);
display.display();
stepDown();
delay(1000);
}
}
void stepDown() {
if (seconds > 0) {
seconds -= 1;
} else {
if (minutes > 0) {
seconds = 59;
minutes -= 1;
} else {
if (hours > 0) {
seconds = 59;
minutes = 59;
hours -= 1;
} else {
trigger();
}
}
}
}
void trigger() {
display.clearDisplay(); // clears the screen and buffer
display.setTextSize(2);
display.setCursor(xPos, yPos);
display.println("Boom");
display.display();
}