Difficulty with a array code and if else statement

got this code working and wanted to add a system of ID numbers that depending on the pattern will send out a different notification. The objective is to be able to enter an ID of 5 numbers with the 6th number symbolizing the type of alert the person wants to send. I keep getting this error- Compilation error: lvalue required as left operand of assignment- and is not sure how to deal with it. thank you for your time.

#include <Keypad.h>
#include <LiquidCrystal.h>
const int RS = 11, EN = 12, D4 = 2, D5 = 3, D6 = 4, D7 = 5;
LiquidCrystal lcd( RS, EN, D4, D5, D6, D7);
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
char keys[4][3] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
byte rowPins[4] = {13, A0, A1, A2}; //connect to the row pinouts of the keypad
byte colPins[3] = {A3, A4, A5}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

const byte bufLen = 6;
byte index = 0;
char buf[bufLen + 1] = "";

void setup(void) {
  Serial.begin(115200);
  lcd.begin(16, 2); // Initialize the LCD
  lcd.setCursor(0, 0);
  lcd.print("Press a key:");
}
void loop(void) {
  evaluateKey(keypad.getKey());
}

void evaluateKey(char aKey) {
  if (!aKey) {  // If no key pressed return immediately
    return;
  }
  switch (aKey) {
    case '*' :  // Clear second line and key buffer
      resetBuffer();
      break;
   case '#' :  // Revert sequence in buffer
      ;
      break;
    default:    // add all other keys to sequence in buffer until buffer full
      addToBuffer(aKey);
      break;
  }
}


void printBuffer() {
  lcd.setCursor(0, 1); // set cursor to second line
  lcd.print(buf);      // print buffer content
}
//make 2 statements like this code; if code is [] retry, if code is [] activated
void addToBuffer(char newKey) { // add newKey to buffer
  if (index < bufLen) {         // but only if index is less than the available buffer size for keys
    buf[index] = newKey;        // Store in buffer at "index"
    buf[index + 1] = 0x00;      // Store a zero in the following char so that print knows where the string ends
    index++;                    // Increment index 
    printBuffer();              // print the updated buffer
  } else {
    lcd.setCursor(0, 0);        // set cursor to second line
    lcd.print(""); // Print sufficient white spaces to clear the line
  }
}


void resetBuffer() {          // Resetting buffer and clear the second line
  index = 0;                  // Resetting the index is sufficient
  lcd.setCursor(0, 0);
  lcd.print("Enter Code:");
  lcd.setCursor(0, 1);        // set cursor to second line
  lcd.print("                 "); // Print sufficient white spaces to clear the line
}

//void invertBuffer() {        // Invert the sequence of characters in the buffer
  //int half;                  // A variable to guide us halfway through the buffer 
  //if (index > 1) {           // Inverting makes only sense if there is more than one character
    //half = index / 2;
    //for (int i = 0; i < half; i++) {
      //char c = buf[i];
      //buf[i] = buf[index - 1 - i];
      //buf[index - 1 - i] = c;
    //}
    //printBuffer();
  //}
//}

  //int array3[6] = {285353, 409563, 672693, 376583, 294873,0}
  //int array2[6] = {285352, 409562, 672692, 376582, 294872,0}
  //int array1[6] = {285351, 409561, 672691, 376581, 294871,0}
  void IDresponce(){
  int array4[6] = {285354, 409564, 672694, 376584, 294874,0};
 if (lcd.print("") = array4) {
  evaluateKey(keypad.getKey());
   (mySerial.available()){ 
    Serial.println(mySerial.readString()); // send from serial to bluetooth 
  } 
  (Serial.available()){ 
    mySerial.println(Serial.readString()); // send from bluetooth to serial 
  } 
 else {
 lcd.print("try again")
 }
}

Copy, paste, and post the entire error message as it will contain additional information.

Please post the complete text of the error message, using code tags.

    if (lcd.print("") = array4)

You are trying to assign the value of the pointer to array4 to the count of how many characters were printed by lcd.print("")

I assume that you meant to use == rather than = but why were you doing the comparison in the first place ?

im doing the comparison cause it is like a password

and here is the entire error code for those that asked, i got rid of the segments that have my name in it:
: In function 'void IDresponce()':
: error: lvalue required as left operand of assignment
if (lcd.print("") = array4) {
^~~~~~
error: 'mySerial' was not declared in this scope
(mySerial.available()){
^~~~~~~~
: note: suggested alternative: 'Serial'
(mySerial.available()){
^~~~~~~~
Serial
error: expected ';' before '{' token
(Serial.available()){
^
error: expected '}' before 'else'
else {
^~~~
: error: expected ';' before '}' token
}
^
Multiple libraries were found for "LiquidCrystal.h"

exit status 1

Compilation error: lvalue required as left operand of assignment

The compiler is right. mySerial is not declared, is it ?

As an aside, what is this line of code supposed to do ?

        (mySerial.available())

Should there be an if in there somewhere ?

alright the advice cleared the errors but there is no signal being sent from the bluetooth

If you have modified the sketch then please post the current version in a new reply


#include <SoftwareSerial.h>
SoftwareSerial mySerial(9,10);
#include <Keypad.h>
#include <LiquidCrystal.h>
const int RS = 11, EN = 12, D4 = 2, D5 = 3, D6 = 4, D7 = 5;
LiquidCrystal lcd( RS, EN, D4, D5, D6, D7);
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
char keys[4][3] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
byte rowPins[4] = {13, A0, A1, A2}; //connect to the row pinouts of the keypad
byte colPins[3] = {A3, A4, A5}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

const byte bufLen = 6;
byte index = 0;
char buf[bufLen + 1] = "";

void setup(void) {
  Serial.begin(115200);
  lcd.begin(16, 2); // Initialize the LCD
  lcd.setCursor(0, 0);
  lcd.print("Press a key:");
  Serial.begin(9600); //open the serial port
  mySerial.begin(9600); // open the bluetooth serial port
}
void loop(void) {
  evaluateKey(keypad.getKey());
}

void evaluateKey(char aKey) {
  if (!aKey) {  // If no key pressed return immediately
    return;
  }
  switch (aKey) {
    case '*' :  // Clear second line and key buffer
      resetBuffer();
      break;
   case '#' :  // Revert sequence in buffer
      ;
      break;
    default:    // add all other keys to sequence in buffer until buffer full
      addToBuffer(aKey);
      break;
  }
}


void printBuffer() {
  lcd.setCursor(0, 1); // set cursor to second line
  lcd.print(buf);      // print buffer content
}
//make 2 statements like this code; if code is [] retry, if code is [] activated
void addToBuffer(char newKey) { // add newKey to buffer
  if (index < bufLen) {         // but only if index is less than the available buffer size for keys
    buf[index] = newKey;        // Store in buffer at "index"
    buf[index + 1] = 0x00;      // Store a zero in the following char so that print knows where the string ends
    index++;                    // Increment index 
    printBuffer();              // print the updated buffer
  } else {
    lcd.setCursor(0, 0);        // set cursor to second line
    lcd.print(""); // Print sufficient white spaces to clear the line
  }
}


void resetBuffer() {          // Resetting buffer and clear the second line
  index = 0;                  // Resetting the index is sufficient
  lcd.setCursor(0, 0);
  lcd.print("");
  lcd.setCursor(0, 1);        // set cursor to second line
  lcd.print("                 "); // Print sufficient white spaces to clear the line
}

//void invertBuffer() {        // Invert the sequence of characters in the buffer
  //int half;                  // A variable to guide us halfway through the buffer 
  //if (index > 1) {           // Inverting makes only sense if there is more than one character
    //half = index / 2;
    //for (int i = 0; i < half; i++) {
      //char c = buf[i];
      //buf[i] = buf[index - 1 - i];
      //buf[index - 1 - i] = c;
    //}
    //printBuffer();
  //}
//}
 
  //int array3[6] = {285353, 409563, 672693, 376583, 294873,0}
  //int array2[6] = {285352, 409562, 672692, 376582, 294872,0}
  //int array1[6] = {285351, 409561, 672691, 376581, 294871,0}
  void IDresponce(){
  int array4[6] = {285354, 409564, 672694, 376584, 294874,0};
 if (0 == array4) {
    evaluateKey(keypad.getKey());
   if(mySerial.available()){ 
    Serial.println(mySerial.readString()); // send from serial to bluetooth 
    } 
    if(Serial.available()){ 
    mySerial.println(Serial.readString()); // send from bluetooth to serial 
    } 
   }
 else {
 lcd.print("try again");
 evaluateKey(keypad.getKey());
   if(mySerial.available()){ 
    Serial.println(mySerial.readString()); // send from serial to bluetooth 
    } 
    if(Serial.available()){ 
    mySerial.println(Serial.readString()); // send from bluetooth to serial 
    }
 }
}


okay i posted the modified sketch but what do i do about the issue of the signals

    int array4[6] = { 285354, 409564, 672694, 376584, 294874, 0 };
    if (0 == array4)

What is the second line above meant to do ?

that is the database of the different codes to be used to send a signal through this device

thats what the array is suppose to do

void IDresponce()

The bluetooth code is in this function which is never called.

So the array holds the list of unsigned integer values to be sent

Some questions

  1. Which Arduino board do you have ?
  2. What is the largest unsigned integer value that an int variable can hold on your Arduino ?
  3. What is the second line of code in reply #12 supposed to do ?

yeah its suppose to be a void loop, and i thought that the loop portion of that statement means you can name it what you want.

im using an ardunio uno, largest value is one that has 7 numbers, and the second line is suppose to check if the integer entered matches one of the integers in the array

I don't know what you mean by that but see int - Arduino Reference Are any of the numbers in the array larger than 32,767 ?

How does it do that ?

how does it do it, uh maybe it looks into the array to see if there is a match and if not goes to the else statement. this is the most complex thing i have coded ever and i am very much a beginner in this.
i shall go check to see if any of the code combinations exceed 32,767.

I suggest you review this information on the use of functions.

https://docs.arduino.cc/learn/programming/functions/