// include the library code:
#include <LiquidCrystal.h>
#include <avr/wdt.h>
// input and output assignments
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
const int intervalButton = 25;
static const int buttonPin = 13;
int previousButtonState = LOW;
int currentButtonState = LOW;
// Boolean Comparisons (True/False Statements)
bool jobState = false;
bool biFold = false;
bool solidCore = false;
bool hollowCore = false;
// Variables
unsigned long hollowCoreTime = 3000;
unsigned long biFoldTime = 6000;
unsigned long solidCoreTime = 9000;
unsigned long buttonPressTime;
unsigned long buttonPressDuration;
unsigned long currentTime;
unsigned long pressTime;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void readButtonState() {
if (currentButtonState == LOW && jobState == false) {
lcd.setCursor(1, 0);
lcd.print("Awaiting Input");
}
if(currentTime - buttonPressTime > intervalButton){
int currentButtonState = digitalRead(buttonPin);
if (currentButtonState == HIGH && previousButtonState == LOW) {
buttonPressTime = currentTime;
previousButtonState = HIGH;
}
if (hollowCore == false && previousButtonState == HIGH) {
if (currentTime - buttonPressTime < hollowCoreTime && buttonPressTime > 0){
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("Hollow Core");
hollowCore = true;
biFold = false;
solidCore = false;
jobState = true;
}
}
if (hollowCore == true && previousButtonState == HIGH) {
if (currentTime - buttonPressTime < biFoldTime && currentTime - buttonPressTime > hollowCoreTime){
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("Bi Fold");
hollowCore = false;
biFold = true;
solidCore = false;
jobState = true;
}
}
if (previousButtonState == HIGH && biFold == true) {
if (currentTime - buttonPressTime > biFoldTime) {
lcd.clear();
lcd.setCursor(3, 0);
lcd.print("Solid Core");
hollowCore = false;
biFold = false;
solidCore = true;
jobState = true;
}
}
if (currentButtonState == LOW && jobState == true) {
delay(1500);
if (hollowCore == true){
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("Hollow Core");
lcd.setCursor(2, 1);
lcd.print("Job Running");
digitalWrite(8, HIGH);
delay(10000);
digitalWrite(8, LOW);
jobState = false;
hollowCore = false;
lcd.clear();
buttonPressTime = currentTime;
previousButtonState = LOW;
}
if (biFold == true){
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("Bi Fold");
lcd.setCursor(2, 1);
lcd.print("Job Running");
digitalWrite(9, HIGH);
delay(10000);
digitalWrite(9, LOW);
jobState = false;
biFold = false;
lcd.clear();
buttonPressTime = currentTime;
previousButtonState = LOW;
}
if (solidCore == true){
lcd.clear();
lcd.setCursor(3, 0);
lcd.print("Solid Core");
lcd.setCursor(2, 1);
lcd.print("Job Running");
digitalWrite(10, HIGH);
delay(10000);
digitalWrite(10, LOW);
jobState = false;
solidCore = false;
lcd.clear();
buttonPressTime = currentTime;
previousButtonState = LOW;
}
}
}
}
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(4, 0);
lcd.print("Masonite");
lcd.setCursor(1, 2);
lcd.print("Device Booting");
// pin assignments
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
delay(2000);
lcd.clear();
}
void loop() {
currentTime = millis();
readButtonState();
delay(5);
}