Was able to find a solution, the working code is below for anyone that may need this as well
Greetings,
This is my first project, so i apologize if my code isn't as buttoned up as it could be. In the current stage of the project, i have three buttons and a LCD screen. I am trying to create two pages on a 16x2 LCD screen that houses four variables. And with a button hold I can change where the cursor blinks and depending on that location I can increase or decrease a specific variable.
button 1 (press): changes what "page" is displayed on LCD
button 1 (hold): changes the cursor location on the screen so a variable can be changed
button 2: increases variable by 1 depending on what case is in affect
button 3: decreases variable by 1 depending on what case is in affect
Through my testing I validated everything in my code works except the lcd.blink().... I am not sure why. But the machine recognizes what case I am in as I can change variables correctly, I just cannot tell where on the LCD the modifications are occurring since the space isn't blinking until a change is made. Any assistance or guidance is always appreciated
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
const int btn1 = 4; // choose the input pin (for pushbutton 1)
const int btn2 = 5; // choose the input pin (for pushbutton 2)
const int btn3 = 6; // choose the input pin (for pushbutton 3)
const int ledwht = A5; // input pin for led
unsigned long tmot = 0; // var for timeout to sleep display
int btn1State = 0; // current state of button 1
int lastBtn1State = 0; // previous state of button 1
int startPressed = 0; // the time button 1 was pressed
int endPressed = 0; // the time button 1 was released
int timeHold = 0; // the time button 1 is hold
int var1 = 0; // the first adjustable variable
int var2 = 0; // second adjustable variable
int var3 = 0; // third adjustable variable
int var4 = 0; // fourth adjustable variable
int SwitchVar = 0; // switch case to change blink cursor for variables
int Display = 0; // switch case for changing the pages
void setup()
{
lcd.begin(16, 2);
lcd.init();
lcd.backlight();
lcd.clear();
pinMode(btn1, INPUT_PULLUP); // declare pushbutton as input
pinMode(btn2, INPUT_PULLUP); // declare pushbutton as input
pinMode(btn3, INPUT_PULLUP); // declare pushbutton as input
pinMode(ledwht, OUTPUT); // declare led as output
}
void loop()
{
btn1State = digitalRead(btn1); // read the pushbutton input pin
if (btn1State != lastBtn1State)
{ // button state changed
if (btn1State == HIGH)
{ // the button was just pressed
startPressed = millis();
}
else
{ // the button was just released
endPressed = millis();
timeHold = endPressed - startPressed;
if (timeHold >= 000 && timeHold < 1000)
{ // button press, this is where you will change the page
lcd.backlight();
tmot = millis() + 10000; // sets timeout time for button inactivity
SwitchVar = 0;
Display ++;
if (Display > 2)
{
Display = 1;
}
}
else if (timeHold >= 1000)
{ // button hold, this is where you will change the variable
lcd.backlight();
tmot = millis() + 10000; // sets timeout time for button inactivity
SwitchVar ++;
if (SwitchVar > 2)
{
SwitchVar = 0;
}
}
}
lastBtn1State = btn1State; // save the current state as the last state, for next time through the loop
switch (Display)
{
case 1:
lcd.init();
lcd.setCursor(0, 0);
lcd.print("PAGE:");
lcd.setCursor(6, 0);
lcd.print(Display);
lcd.setCursor(9, 0);
lcd.print("SWTC");
lcd.setCursor(15, 0);
lcd.print(SwitchVar);
lcd.setCursor(0, 1);
lcd.print("VAR1:");
lcd.setCursor(6, 1);
lcd.print(var1);
lcd.setCursor(9, 1);
lcd.print("VAR2:");
lcd.setCursor(15, 1);
lcd.print(var2);
switch (SwitchVar)
{
case 0:
lcd.setCursor(15, 1);
lcd.noBlink();
break;
case 1:
lcd.setCursor(6, 1);
lcd.blink();
break;
case 2:
lcd.setCursor(15, 1);
lcd.blink();
break;
}
break;
case 2:
lcd.init();
lcd.setCursor(0, 0);
lcd.print("PAGE:");
lcd.setCursor(6, 0);
lcd.print(Display);
lcd.setCursor(0, 1);
lcd.print("VAR3:");
lcd.setCursor(6, 1);
lcd.print(var3);
lcd.setCursor(9, 1);
lcd.print("VAR4:");
lcd.setCursor(15, 1);
lcd.print(var4);
switch (SwitchVar)
{
case 0:
lcd.setCursor(15, 1);
lcd.noBlink();
break;
case 3:
lcd.setCursor(6, 1);
lcd.blink();
break;
case 4:
lcd.setCursor(15, 1);
lcd.blink();
break;
}
break;
}
}
else
{
if (millis() > tmot && tmot != 0)
{
tmot = 0;
Display = 0;
SwitchVar = 0;
lcd.noBacklight();
}
}
switch (SwitchVar)
{
case 0:
lcd.setCursor(15, 1);
lcd.noBlink();
break;
case 1:
lcd.setCursor(6, 1);
lcd.blink();
if ((digitalRead(btn2) == HIGH) && (Display == 1))
{
delay(500); // delay to debounce switch
tmot = millis() + 10000; // sets timeout time for button inactivity
var1++;
if (var1 > 9)
{
var1 = 0;
}
lcd.print(var1);
}
else if ((digitalRead(btn2) == HIGH) && (Display == 2))
{
delay(500); // delay to debounce switch
tmot = millis() + 10000; // sets timeout time for button inactivity
var3++;
if (var3 > 9)
{
var3 = 0;
}
lcd.print(var3);
}
if ((digitalRead(btn3) == HIGH) && (Display == 1))
{
delay(500); // delay to debounce switch
tmot = millis() + 10000; // sets timeout time for button inactivity
var1--;
if (var1 < 0)
{
var1 = 0;
}
lcd.print(var1);
}
else if ((digitalRead(btn3) == HIGH) && (Display == 2))
{
delay(500); // delay to debounce switch
tmot = millis() + 10000; // sets timeout time for button inactivity
var3--;
if (var3 < 0)
{
var3 = 0;
}
lcd.print(var3);
}
break;
case 2:
lcd.setCursor(15, 1);
lcd.blink();
if ((digitalRead(btn2) == HIGH) && (Display == 1))
{
delay(500); // delay to debounce switch
var2++;
if (var2 > 9)
{
var2 = 0;
}
lcd.print(var2);
}
else if ((digitalRead(btn2) == HIGH) && (Display == 2))
{
delay(500); // delay to debounce switch
var4++;
if (var4 > 9)
{
var4 = 0;
}
lcd.print(var4);
}
if ((digitalRead(btn3) == HIGH) && (Display == 1))
{
delay(500); // delay to debounce switch
var2--;
if (var2 < 0)
{
var2 = 0;
}
lcd.print(var2);
}
else if ((digitalRead(btn3) == HIGH) && (Display == 2))
{
delay(500); // delay to debounce switch
var4--;
if (var4 < 0)
{
var4 = 0;
}
lcd.print(var4);
}
break;
}
}