I am extremely new to coding with Arduino and have run into a problem.
I am attempting to use a DFRobot LCD Keypad Shield with an Arduino Mega 2560.
The ultimate goal is to have three counters on one screen. I would like to be able to use the “LEFT” and “RIGHT” buttons on the shield to move the cursor between the three different counters and use the “UP” and “DOWN” buttons to increment/decrease the displayed value of the selected counters.
Currently, the issue I have run into is trying to get the cursor to move only to selected positions on the line in which the counters are located. It seems that every time I think I have solved the issue, the code gives me a new error code. Any help would be greatly appreciated.
The code that I have is as follows:
// The goal of this project is to utilize the LCD shield to display three counters. The “LEFT” and
// “RIGHT” buttons should allow user to scroll between counters while the “UP” and “DOWN” buttons
// increase or decrease the displayed number.
// include the Liquid Crystal library code
// Initialize the library with interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// Variables that change for counters
int CPCounter = 0; // Counter for Command Points
int VPCounter = 0; // Counter for Victory Points
int TNCounter = 0; // Counter for Turns
//keypad button variables
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
int read_LCD_buttons() // read the buttons
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
// We make this the 1st option for speed reasons since it will be the most likely result
if (adc_key_in > 1000) return btnNONE;
// For V1.1 us this threshold
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;
return btnNONE; // when all others fail, return this.
// Set up the LCD’s number of columns and rows:
// Print first line of static words
// Print second line of static words
} // End Void Setup
lcd_key = read_LCD_buttons();
} // End Void Loop
Again, I greatly appreciate any and all help as I am extremely new to this.