Dear all,
I´m working around a Display Menu for my needs and i´m not the best code writer. After Googling and trying a lot of examples i could find and build something that i can use for the start.
The idea is that i can change the value of 2 counters and 2 timers over the sreen with buttons.
How the code is right now it´s possible to change the values individuality. + or - 1000 cycles and + or - 1000 millisec.
unsigned long parameters[numOfScreens] = {1000};
But what i would like to have would be a individual value changing for the 2 counter and that i could choose over a option being 10, 100, 1000 or 10000 steps increasing or decreasing the counters. I have tried already to make it work but i´m reaching my coding limits. I would be thankful for some help. Of couse if there is a better way than the one that i´m going now with my code, i would be also thankful for some suggestions.
Follows down the code that i have until now
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//Input & Button Logic
const int numOfInputs = 3;
const int inputPins[numOfInputs] = {6,7,8};
int inputState[numOfInputs];
int lastInputState[numOfInputs] = {LOW,LOW,LOW};
bool inputFlags[numOfInputs] = {LOW,LOW,LOW};
long lastDebounceTime[numOfInputs] = {0,0,0};
long debounceDelay = 5;
/////////////////////////////////////////////////////
//LCD Menu Logic
const int numOfScreens = 4;
int currentScreen = 0;
String screens[numOfScreens][2] = { {"Counter1", "Cycles"}, {"Counter2", "Cycles"}, {"Timer1","MiliSec."}, {"Timer2","MiliSec."}};
unsigned long parameters[numOfScreens] = {500};
//////////////////////////////////////////////////////
void setup()
{
for(int i = 0; i < numOfInputs; i++) {
pinMode(inputPins[i], INPUT);
digitalWrite(inputPins[i], HIGH); // pull-up 20k
}
Serial.begin(9600);
lcd.begin(16, 3);
lcd.setCursor(0,0);
lcd.print(":::Menu:::");
lcd.setCursor(5,1);
}
//////////////////////////////////////////////////////
void loop()
{
setInputFlags();
resolveInputFlags();
}
//////////////////////////////////////////////////////
void setInputFlags()
{
for(int i = 0; i < numOfInputs; i++) {
int reading = digitalRead(inputPins[i]);
if (reading != lastInputState[i]) {
lastDebounceTime[i] = millis();
}
if ((millis() - lastDebounceTime[i]) > debounceDelay) {
if (reading != inputState[i]) {
inputState[i] = reading;
if (inputState[i] == HIGH) {
inputFlags[i] = HIGH;
}
}
}
lastInputState[i] = reading;
}
}
/////////////////////////////////////////////////////
void resolveInputFlags()
{
for(int i = 0; i < numOfInputs; i++) {
if(inputFlags[i] == HIGH) {
inputAction(i);
inputFlags[i] = LOW;
printScreen();
}
}
}
///////////////////////////////////////////////////////
void inputAction(int input)
{
if(input == 0) {if (currentScreen == 0) {currentScreen = numOfScreens-1;}
else{currentScreen--;}}
else if(input == 1) {
parameterChange(0);
}else if(input == 2) {
parameterChange(1);
}
}
////////////////////////////////////////////////////////
void parameterChange(int key) {
if(key == 0) {
parameters[currentScreen] = parameters[currentScreen]+500;
}else if(key == 1) {
parameters[currentScreen] = parameters[currentScreen]-500;
}
}
////////////////////////////////////////////////////////
void printScreen() {
lcd.clear();
lcd.print(screens[currentScreen][0]);
lcd.setCursor(0,1);
lcd.print(parameters[currentScreen]);
lcd.print(" ");
lcd.print(screens[currentScreen][1]);
}
The code how it´s right now works fine