Hi there,
I am still having issues with the while loop. After I press the '#' key I can still go back and enter new values for each of the positions. I put the while loop in the setup and after I press the '#' key I want it to go in the Void Loop. Instead, it looks like afterwards, I can re-enter values.
How would I make my While Loop valid only in the Void Setup and after I press the '#' key, lock those values and take me into the Void Loop?
include <Wire.h>
#include <LCD.h>
#include<LiquidCrystal_I2C.h>
#include <Keypad.h>
int valueA = 0;
int valueB = 0;
int valueC = 0;
int valueD = 0;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four colums
//define the smybols on the buttons of the keyboard
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[COLS] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[ROWS] = {6,7,8,9}; //connect to the colum pinouts of the keypad
//initalize an instance of class NewKeypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7,3,POSITIVE);
//0x3F is 20 by 4 LCD
LiquidCrystal_I2C lcd2(0x3E,2,1,0,4,5,6,7,3,POSITIVE);
//0x3E is 16 by 2 LCD
void setup() {
// put your setup code here, to run once:
//Display messages for (0x3F) 20 by 4 LCD
lcd.backlight();
lcd.begin(20,4);
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Pin A");
lcd.setCursor(17,0);
lcd.print("mm");
lcd.setCursor(0,1);
lcd.print("Pin B");
lcd.setCursor(17,1);
lcd.print("mm");
lcd.setCursor(0,2);
lcd.print("Pin C");
lcd.setCursor(17,2);
lcd.print("mm");
lcd.setCursor(0,3);
lcd.print("MOTOR Speed");
lcd.setCursor(17,3);
lcd.print("RPM");
//Display messages for (0x3E) 16 by 2 LCD
lcd2.begin(16,2);
lcd2.backlight();
lcd2.setCursor(0, 0);
lcd2.print("Press # to Start");
lcd2.setCursor(0,1);
lcd2.print("Press * for Home");
while (keys != '#') {
static int number = 0;
char key = keypad.waitForKey();
switch(key)
{
case '0'...'9':
number *= 10;
number += key - '0';
break;
case 'A':
useForCaseA(number);
number = 0;
break;
case 'B':
useForCaseB(number);
number = 0;
break;
case 'C':
useForCaseC(number);
number = 0;
break;
case 'D':
useForCaseD(number);
number = 0;
break;
case '*': // Set Home Position
break;
case '#': // Move Motors on Position and Start Test
StartMessage();
loop();
break;
}
}
}
void loop() {
//Another Code
}
void StartMessage() {
lcd2.clear();
lcd2.begin(16,2);
lcd2.backlight();
lcd2.setCursor(0, 0);
lcd2.print("No of Cycles:");
}
void useForCaseA(int num){
valueA = num;
if((valueA >= 1) && (valueA <= 6000)){
lcd.setCursor(10,0);
lcd.print(" ");
lcd.setCursor(10,0);
lcd.print(valueA);
}else{
lcd.setCursor(10,0);
lcd.print(" ");
lcd.setCursor(10,0);
lcd.print(valueA);
valueA=0;
ErrorMessage();
lcd.setCursor(10,0);
lcd.print(" ");
lcd.setCursor(10,0);
lcd.print(valueA);
}
}
void useForCaseB(int num){
valueB = num;
if((valueB >= 1) && (valueB <= 6000)){
lcd.setCursor(10,1);
lcd.print(" ");
lcd.setCursor(10,1);
lcd.print(valueB);
}else{
lcd.setCursor(10,1);
lcd.print(" ");
lcd.setCursor(10,1);
lcd.print(valueB);
valueB=0;
ErrorMessage();
lcd.setCursor(10,1);
lcd.print(" ");
lcd.setCursor(10,1);
lcd.print(valueB);
}
}
void useForCaseC(int num){
valueC = num;
if((valueC >= 1) && (valueC <= 6000)){
lcd.setCursor(10,2);
lcd.print(" ");
lcd.setCursor(10,2);
lcd.print(valueC);
}else{
lcd.setCursor(10,2);
lcd.print(" ");
lcd.setCursor(10,2);
lcd.print(valueC);
valueC=0;
ErrorMessage();
lcd.setCursor(10,2);
lcd.print(" ");
lcd.setCursor(10,2);
lcd.print(valueC);
}
}
void useForCaseD(int num){
valueD = num;
if((valueD >= 100) && (valueD <= 600)){
lcd.setCursor(13,3);
lcd.print(" ");
lcd.setCursor(13,3);
lcd.print(valueD);
}else{
lcd.setCursor(13,3);
lcd.print(" ");
lcd.setCursor(13,3);
lcd.print(valueD);
valueD=0;
ErrorMessage();
lcd.setCursor(13,3);
lcd.print(" ");
lcd.setCursor(13,3);
lcd.print(valueD);
lcd.setCursor(17,3);
lcd.print("RPM");
}
}
void ErrorMessage(){
//Display messages for (0x3E) 16 by 2 LCD
lcd2.clear();
lcd2.setCursor(2,0);
lcd2.print("ERROR Check");
lcd2.setCursor(1,1);
lcd2.print("Values Entered");
delay(10000);
lcd2.clear();
lcd2.begin(16,2);
lcd2.backlight();
lcd2.setCursor(0, 0);
lcd2.print("Press # to Start");
lcd2.setCursor(0,1);
lcd2.print("Press * for Home");
}
Many thanks again