I am still having problems with my Switch Case options function so what I have done is isolated it from my main program onto a Scratchpad sketch so as it isn't influenced by anything else.
the code is below and the problem I am having is that I cannot stop it from freewheeling through the case options without a button press from digitalRead(P_0).
I have battled on with this for a good while now and cannot make any headway with it. Could someone kindly put me out of my agony.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
LiquidCrystal_I2C lcd(0x3F, 20, 4); // 20x4 LCD Display
// constants won't change. They're used here to set pin numbers:
const int P_0 = 10; // the number of the pushbutton pin
const int P_1 = 9;
const int P_2 = 8;
const int P_3 = 7;
const int P_4 = 6;
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int var = 0;
int Count = 0;
int ButtonPress = 0;
int menu = 0;
int XStepsPermm = 0;
int YStepsPermm = 0;
int ZStepsPermm = 0;
void setup() {
lcd.begin();
lcd.backlight();
lcd.clear();
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(P_0, INPUT); // Select
pinMode(P_1, INPUT); // Left
pinMode(P_2, INPUT); // Up
pinMode(P_3, INPUT); // Down
pinMode(P_4, INPUT); // Right
pinMode(P_0, INPUT_PULLUP);
pinMode(P_1, INPUT_PULLUP);
pinMode(P_2, INPUT_PULLUP);
pinMode(P_3, INPUT_PULLUP);
pinMode(P_4, INPUT_PULLUP);
XStepsPermm = EEPROM.read(1);
YStepsPermm = EEPROM.read(2);
ZStepsPermm = EEPROM.read(3);
}
void loop() {
// void EditParams() {
// lcd.setCursor(2, 0);
// lcd.print("Surface Grinder");
// lcd.setCursor(5, 1);
// lcd.print("MAIN MENU");
// ************** PARAMETERS ***************
// EDIT PARAMETERS
//modus = X Steps per mm || Y Steps/mm || Z Steps per mm || Return
// lcd.clear();
if(digitalRead(P_0)== LOW)
{
Count = Count + 1; }
delay (500);
if (Count >= 4) {
Count == 0; }
switch (Count) {
//-------------EDIT X--------------------
case 0:
lcd.setCursor(2,0);
lcd.print("EDIT X PARAMETERS");
lcd.setCursor(0,2);
lcd.print("> Set 'X' Steps/mm");
lcd.setCursor(7,3);
lcd.print("<");
lcd.setCursor(9,3);
lcd.print (XStepsPermm);
lcd.setCursor(13,3);
lcd.print(">");
// delay (200);
if(digitalRead(P_2)== LOW)
{
XStepsPermm++; // Increment the Count by 1
}
delay (300);
if(digitalRead(P_3)== LOW)
{
XStepsPermm--; // Decrement the Count by 1
}
if (XStepsPermm <=99) {
lcd.setCursor(11,3); //Blank trailing zero
lcd.print (" ");
}
delay (200);
if(digitalRead(P_0)== LOW)
{
EEPROM.write(1, XStepsPermm);
break;
lcd.clear();
}
//-------------EDIT Y--------------------
case 1:
lcd.setCursor(2,0);
lcd.print("EDIT Y PARAMETERS");
lcd.setCursor(0,2);
lcd.print("> Set 'Y' Steps/mm");
lcd.setCursor(7,3);
lcd.print("<");
lcd.setCursor(9,3);
lcd.print (YStepsPermm);
lcd.setCursor(13,3);
lcd.print(">");
if(digitalRead(P_2)== LOW) // if the pushbutton P2 (Up) is pressed.
{
YStepsPermm++; } // Increment the Count by 1
delay (200);
if(digitalRead(P_3)== LOW) // if the pushbutton P2 (Up) is pressed.
{
YStepsPermm--; // Decrement the Count by 1
}
if (YStepsPermm <=99) {
lcd.setCursor(11,3); //Blank trailing zero
lcd.print (" ");
}
delay (200);
if(digitalRead(P_0)== LOW)
{
EEPROM.write(2, YStepsPermm);
break;
}
// delay (200);
lcd.clear();
//-------------EDIT Z--------------------
case 2:
lcd.setCursor(2,0);
lcd.print("EDIT Z PARAMETERS");
lcd.setCursor(0,2);
lcd.print("> Set 'Z' Steps/mm");
lcd.setCursor(7,3);
lcd.print("<");
lcd.setCursor(9,3);
lcd.print (ZStepsPermm);
lcd.setCursor(13,3);
lcd.print(">");
if(digitalRead(P_2)== LOW)
{ // check if the pushbutton P2 (Up) is pressed.
ZStepsPermm++; } // Increment the Count by 1
delay (200);
if(digitalRead(P_3)== LOW)
{
YStepsPermm--; } // Decrement the Count by 1
if (ZStepsPermm <=99) { //Blank trailing zero
lcd.setCursor(11,3);
lcd.print (" "); }
delay (300);
if(digitalRead(P_0)== LOW)
{
EEPROM.write(3, ZStepsPermm);
break;
}
delay (300);
}
}