Cant get if then statement to work

I have tried everything I know and have looked over the Arduino Forum for about 45min now and can not figure out whats wrong. I should press the #1 on the keypad and it should display on an lcd the text but i keep getting error messages with the if statement.

Here is the code:

#include <Key.h>
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const byte ROWS = 4;
const byte COLS = 4;

// Key array
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

// Connections to Arduino (digital pins on MEGA2560 R3)
byte rowPins[ROWS] = {22, 24, 26, 28};
byte colPins[COLS] = {30, 32, 34, 36
};

// Create keypad object
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
}

void loop() {
if (Keypad = '1');
{
lcd.write("apple watch product#1234567890");
delay(10000000000000000000000000000000);
}
{
else lcd.write("scan Product");
}

Have a look at an example Keypad sketch that comes with the Keypad library. You should see the difference right away.

I can see the examples but i dont see how it would work for me, I want to have each of the 16 buttons be a "product" and each make the lcd say something different. I dont quite understand how it would determine which button is being pressed as i didnt see any numbers of letters in the if-then statement of the example.

barrettt:
delay(10000000000000000000000000000000);

What the- What is this?!?!?
You code DEFINITELY won't work because of this rubbish.

I fixed the delay and it still does not work, could you please help me with fixing the if then statement?

barrettt:
I can see the examples but i dont see how it would work for me, I want to have each of the 16 buttons be a "product" and each make the lcd say something different. I dont quite understand how it would determine which button is being pressed as i didnt see any numbers of letters in the if-then statement of the example.

Possibly you have the wrong example. I am totally working off memory, but I think one example sends key presses as different characters sent to the serial output, where you can read them. That might help.

the 10000000000000000000000000000 line should be

while(1);

I fixed the delay and it still does not work, could you please help me with fixing the if then statement?

It's so bad that it would be better for you to go back to the example and work from there. Look for lines that seem to be key input.

Ok, Ill try

Here is the new code, i keep getting the error "expression cannot be used as a function"

#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A','B'},
{'C','D','E','F'}
};
byte rowPins[ROWS] = {22, 24, 26, 28}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {30, 32, 34, 36}; //connect to the column pinouts of the keypad

Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup(){
lcd.begin(16, 2);
Serial.begin(9600);
}

void loop(){
char customKey = customKeypad.getKey();

if (customKey){
Serial.println(customKey);
}
if(Serial.print=1();
lcd.write("apple watch product#1234567890");
}

Why does nobody ever Read this before posting a programming question.

I see your problem with about .5 seconds of looking- it's terribly obvious. Post your code using code tags and if you still can't see it, I'll enlighten you.

if(Serial.print=1();

Well that's messed up.

Actually, I've never read the "Read this before posting a programming question." either.

-jim lee

@barrettt

Are you going for:

if ( customKey == 1 ) {
      lcd.write("apple watch                             product#1234567890");
}

I still cant get it , I want it to pull the data from the serial monitor and Have an If then statement for 16 different "products", Im not sure how to pull the data from the serial monitor apparently because it just wont work. Could someone please suggest how to fix the code?

Sorry for any mistakes , I am pretty new to coding.

The code:

#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'0','1','2','3'},
  {'4','5','6','7'},
  {'8','9','A','B'},
  {'C','D','E','F'}
};
byte rowPins[ROWS] = {22, 24, 26, 28}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {30, 32, 34, 36}; //connect to the column pinouts of the keypad


Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup(){
   lcd.begin(16, 2);
  Serial.begin(9600);
}
 
void loop(){
  char customKey = customKeypad.getKey();
   
  if (customKey){
    Serial.println(customKey);
  }
  if(Serial.print=1();
   lcd.write("apple watch                             product#1234567890");
}

What does the serial monitor have to do with it?

You have read the keyboard so how about comparing customKey to '1'

Could you please explain how to do that? Like I said Im pretty new to coding.

if (customKey == '1')

You have a Serial.println(customkey) in your program. What values does it show you on the serial monitor? Maybe the value of the key you just pressed?

Steve

Why does nobody ever Read this before posting a programming question. read the tutorials, examples and documentation?

I changed that but it still does not work

I can see the examples but i dont see how it would work for me

Thing is, you don't really have to see anything. You can practically cut and paste the correct syntax from almost any example sketch. The line you're messing up is practically the same in every one.

barrettt:
I changed that but it still does not work

But you didn't show us your changed sketch. So my guess is that whatever "that" you changed either wasn't the right "that" or you didn't change it properly.

Steve