#include <LiquidCrystal.h>
LiquidCrystal lcd(7,6,5,4,3,2);
const byte HOURGLASS_TOP[8] = {
0b11111,
0b11111,
0b01110,
0b00100,
0b01010,
0b10001,
0b11111,
0b00000
};
const byte HOURGLASS_MIDDLE[8] = {
0b11111,
0b10001,
0b01110,
0b00100,
0b01110,
0b10001,
0b11111,
0b00000
};
const byte HOURGLASS_BOTTOM[8] = {
0b11111,
0b10001,
0b01010,
0b00100,
0b01110,
0b11111,
0b11111,
0b00000
};
volatile byte currentImage = 0;
volatile bool enableTimer = true;
volatile unsigned long currentTime;
void setup() {
lcd.createChar(0, HOURGLASS_TOP);
lcd.createChar(1, HOURGLASS_MIDDLE);
lcd.createChar(2, HOURGLASS_BOTTOM);
lcd.begin(16,2);
//pull-up resistors activated
pinMode(20, INPUT);
pinMode(21, INPUT);
digitalWrite(20, HIGH);
digitalWrite(21, HIGH);
// Attach ISRs to the interrupts corresponding to pins 21 and 20 (INT0 and INT1)
attachInterrupt(digitalPinToInterrupt(20), startStopTimer, RISING);
attachInterrupt(digitalPinToInterrupt(21), resetTimer, RISING);
}
void loop() {
if (enableTimer) {
displayValue();
displayImage();
currentTime++;
if (currentImage == 2) {
currentImage = 0;
} else {
currentImage++;
}
delay(1000);
}
}
void displayValue() {
lcd.setCursor(0,0);
lcd.print(currentTime);
}
void displayImage() {
lcd.setCursor(0,1);
lcd.write(currentImage);
}
// First ISR function
void startStopTimer() {
enableTimer = !enableTimer;
}
// Second ISR function
void resetTimer() {
lcd.clear();
currentTime = 0;
currentImage = 0;
displayValue();
displayImage();
}