Hi,
I have alot going on in this code from controlling a motor, a keypad, light curtain, and I am trying to add to write code to turn the light curtain on or off. I am trying to use a variable value to determine which code it picks to run. I have included the full code although right now I am only trying to get the Variable section to work right at the start of the loop. I wanted the variable to be at 0 initially, then while it is at 0 with the question up on the display, I would like to pick A or B which would write a 1 or 2 to the variable. I am having an odd issue. When I select B it will change the variable to 2 in the serial monitor, but when I select A it does not change it to 1. Any ideas why this would happen. Sorry about the mess of code. I know it is not clean. I am a hardware guy tinkering with software until things work. I had to cut off the light curtain section of code because it was too long. This may screw up how many brackets are at the end of the code. Thanks for the help.
#include <Keypad.h>
#include <Wire.h>
#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
#define WHITE 0x7 //Set Up Color
//const byte ROWS = 4; //4 Rows Across
//const byte COLS = 3; // 3 Columns up and down
//char hexaKeys[ROWS][COLS] = { //Shows the pattern of the Keypad
// {'1', '2', '3'},
//{'4', '5', '6'},
//{'7', '8', '9'},
// {'*', '0', '#'}
//};
//byte rowPins[ROWS] = {8, 7, 6, 5}; //Assigning Arduino Pins Used {8, 7, 6, 5}
//byte colPins[COLS] = {4, 3, 2}; // Assigning Arduino Pins Used
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
char Alarm;
char keyArray[5] = {'0', '0', '0', '0'}; //
int arrayPos = 0; //
int inputPWM = 0; //
int inputVariable1 = 0;
//const int threshold = 1;
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
int PWMoutput = 10;
//int Motorstop = 12;
void setup(){
Serial.begin(9600); // baud rate
char customKey = customKeypad.getKey(); //
lcd.begin(16, 2); //Defines how many characters in each row and how many rows
lcd.setCursor(0,0); //Setting Print to first character and first row
lcd.print ("Push A SAFE");
lcd.setCursor(0,1);
lcd.print ("Push B UNSAFE");
// lcd.print ("Select RPM Speed"); //Printing This Text on Top Row
//lcd.print(customKey);
//lcd.setBacklight(WHITE);
lcd.setCursor(0, 1); // Setting up cursor to print on first character of 2nd row
}
uint8_t i=0;
void loop()
{
char customKey = customKeypad.getKey();
Serial.println(inputVariable1);
Serial.println(customKey);
while (inputVariable1 == '0')
{if (customKey == 'A')
inputVariable1 = 1; //this is the part that I can't get to work
if (customKey == 'B')
inputVariable1 = 2;}
}