HOW TO DECLARE A VARIABLE FROM MATRIX KEYPAD ENTRY TO CHECK ENCODER AGAINST

Hello all! I am trying to figure out a new project. I have a tubing bender that I am making that has a remote operated solenoid valve and am trying to use an Arduino to input the desired bend angle and check it against a LPD3806-360BM rotary encoder that will be connected to the shaft. When it reaches the angle the relay will stop once the desired angle is reached. However, I'm not sure how to declare the variable from the set_Degrees function into the loop. It is not in the setup function so I believe it is a global variable. Any help is appreciated!

[code]

#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define enc_a 2
#define enc_b 3

int CYLINDER_EXTEND = 13;
int CYLINDER_RETRACT = 12;
volatile int encoderValue = 0;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'.', '0', '#', 'D'}
};
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x20 for a 16 chars and 2 line display
byte rowPINS[ROWS] = {4, 5, 6, 7};
byte colPINS[COLS] = {8, 9, 10, 11};

Keypad kpd = Keypad(makeKeymap(keys), rowPINS, colPINS, ROWS, COLS);

void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
  asm volatile (" jmp 0");
}

float set_Degrees()  {
  int i = 0;
  int counter = 0;
  float Degrees = 0;
  float Bend_Angle = 0;
  float num = 0.00;
  float decimal = 0.00;
  float decnum = 0.00;
  float val = 0.00;
  lcd.clear();
  char key = kpd.getKey();
  lcd.setCursor(0, 1); lcd.print("Enter BendAngle:"); lcd.setCursor(0, 3); lcd.print("OK= # "); lcd.print((char)60); lcd.print((char)45); lcd.print(" D");
  lcd.setCursor(17, 2);
  bool decOffset = false;


  while (key != '#')
  {
    switch (key)
    {
      case NO_KEY:
        break;

      case '.':
        if (!decOffset)
        {
          decOffset = true;
        }
        lcd.print(key);
        break;

      case 'D':
        num = 0.00;
        lcd.setCursor(16, 2); lcd.print(" ");
        lcd.setCursor(16, 2);
        break;

      case '0': case '1': case '2': case '3': case '4':
      case '5': case '6': case '7': case '8': case '9':
        if (!decOffset)
        {
          num = num * 10 + (key - '0');
          lcd.print(key);
        }
        else if ((decOffset) && (counter <= 1))
        {
          num = num * 10 + (key - '0');
          lcd.print(key);
          counter++;
        }
        break;
    } //end case
    if (num >= 181)
    {
      lcd.clear();
      lcd.setCursor(0, 0); lcd.print("EXCEED MAX PARAMETER");   //The bender will bend tubing 180 degrees in one operation but not more than 180. Software limit
      delay(5000);
      software_Reset();
    }
    decnum = num / pow(10, counter);
    key = kpd.getKey();
  } //end while not #

  return decnum;   //I need the value from the keypad entry to be saved to the variable last_Degrees and passed into the if-statements to compare to the encoder value
}

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.backlight(); lcd.print("JIMS MACHINE SERVICE");
  lcd.setCursor(4, 2); lcd.print("TUBING BENDER");
  lcd.setCursor(3, 3); lcd.print("COPYRIGHT  2020");
  delay(2000);
  lcd.clear();
  set_Degrees();
  pinMode(CYLINDER_EXTEND, OUTPUT);
  pinMode(CYLINDER_RETRACT, OUTPUT);
  pinMode(enc_a, INPUT_PULLUP);
  pinMode(enc_b, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(enc_a), encoder, FALLING);
  attachInterrupt(digitalPinToInterrupt(enc_a), encoder, FALLING);

}


void loop() {
  lcd.setCursor(0, 1); lcd.print("                "); // These two lines are to clear the screen without having a lcd.clear inside the loop?
  lcd.setCursor(4, 3); lcd.print("      ");
  char key = kpd.getKey();
  float decnum;
  float Degrees = encoderValue * .5;            //The encoder value is multiplied by .5 because the quadrature encoder doubles the value that I actually want.
  float set_Degrees ; //STATIC
  while (Degrees != set_Degrees)
  {
    //set_Degrees = Degrees;
    lcd.setCursor(1, 0); lcd.print("Industrial  Bender");
    lcd.setCursor(0, 2); lcd.print("Ent.Angle:"); lcd.setCursor(11, 2); lcd.print("Bend Ang:");
    lcd.setCursor(0, 3); lcd.print(decnum); //changed to write instead of print?
    lcd.setCursor(7, 3); lcd.print("*");
    lcd.setCursor(12, 3); lcd.print(encoderValue * .5);
  }

  if (Degrees >= set_Degrees) {
    digitalWrite(CYLINDER_EXTEND, HIGH);    // Here the last_degrees variable, the entered value, checks with the encoder.
    digitalWrite(CYLINDER_RETRACT, LOW);     //
    encoderValue == set_Degrees;
  }
  if (Degrees == set_Degrees) {

    digitalWrite(CYLINDER_RETRACT, HIGH);     //send bender home after bending operation.
    digitalWrite(CYLINDER_EXTEND, LOW);
    set_Degrees = 0;
  }

}
void encoder() {
  if (digitalRead(enc_a) == digitalRead(enc_b)) {
    encoderValue++;
  }
  else {
    encoderValue--;
  }
}

[/code]

Your sketch is triggering a LOT of compiler warnings. You should look them over to see how many you can fix. You can comment out (or just delete) the unused variables.

/Users/john/Documents/Arduino/sketch_dec12a/sketch_dec12a.ino: In function 'float set_Degrees()':
/Users/john/Documents/Arduino/sketch_dec12a/sketch_dec12a.ino:32:7: warning: unused variable 'i' [-Wunused-variable]
   int i = 0;
       ^
/Users/john/Documents/Arduino/sketch_dec12a/sketch_dec12a.ino:34:9: warning: unused variable 'Degrees' [-Wunused-variable]
   float Degrees = 0;
         ^~~~~~~
/Users/john/Documents/Arduino/sketch_dec12a/sketch_dec12a.ino:35:9: warning: unused variable 'Bend_Angle' [-Wunused-variable]
   float Bend_Angle = 0;
         ^~~~~~~~~~
/Users/john/Documents/Arduino/sketch_dec12a/sketch_dec12a.ino:37:9: warning: unused variable 'decimal' [-Wunused-variable]
   float decimal = 0.00;
         ^~~~~~~
/Users/john/Documents/Arduino/sketch_dec12a/sketch_dec12a.ino:39:9: warning: unused variable 'val' [-Wunused-variable]
   float val = 0.00;
         ^~~
/Users/john/Documents/Arduino/sketch_dec12a/sketch_dec12a.ino: In function 'void loop()':
/Users/john/Documents/Arduino/sketch_dec12a/sketch_dec12a.ino:139:18: warning: value computed is not used [-Wunused-value]
     encoderValue == set_Degrees;
     ~~~~~~~~~~~~~^~~~~~~~~~~~~~
/Users/john/Documents/Arduino/sketch_dec12a/sketch_dec12a.ino:121:8: warning: unused variable 'key' [-Wunused-variable]
   char key = kpd.getKey();
        ^~~
/Users/john/Documents/Arduino/sketch_dec12a/sketch_dec12a.ino:125:18: warning: 'set_Degrees' is used uninitialized in this function [-Wuninitialized]
   while (Degrees != set_Degrees)
          ~~~~~~~~^~~~~~~~~~~~~~
/Users/john/Library/Arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino/main.cpp: In function 'main':
/Users/john/Library/Arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino/Print.cpp:111:30: warning: 'decnum' may be used uninitialized in this function [-Wmaybe-uninitialized]
   return printFloat(n, digits);
                              ^
/Users/john/Documents/Arduino/sketch_dec12a/sketch_dec12a.ino:122:9: note: 'decnum' was declared here
   float decnum;
         ^

Something like this

#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define enc_a 2
#define enc_b 3

int CYLINDER_EXTEND = 13;
int CYLINDER_RETRACT = 12;
volatile int encoderValue = 0;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'.', '0', '#', 'D'}
};
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x20 for a 16 chars and 2 line display
byte rowPINS[ROWS] = {4, 5, 6, 7};
byte colPINS[COLS] = {8, 9, 10, 11};

Keypad kpd = Keypad(makeKeymap(keys), rowPINS, colPINS, ROWS, COLS);

float bendDegrees;

void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
  asm volatile (" jmp 0");
}

float set_Degrees()  {
  // get desired bend angle as nnn.n
  // maximum of 3 digits before decimal
  // optional decimal
  // at most 1 digit after decimal

  int count = 0;
  float num = 0.00;

  lcd.clear();
  lcd.setCursor(0, 1);
  lcd.print("Enter Angle:");
  lcd.setCursor(0, 3);
  lcd.print("OK= # <- D");
  lcd.setCursor(17, 2);
  bool decOffset = false;

  char key = kpd.getKey();

  while (key != '#') {
    switch (key) {
      case NO_KEY:
        break;

      case '.':
        if (!decOffset) {
          decOffset = true;
          count = 0;
          lcd.print(key);
        }
        break;

      case 'D':
        num = 0.00;
        decOffset = false;
        count = 0;
        lcd.setCursor(12, 2);
        lcd.print("      ");
        lcd.setCursor(12, 2);
        break;

      case '0': case '1': case '2': case '3': case '4':
      case '5': case '6': case '7': case '8': case '9':
        if (!decOffset && count < 3) {
          count++;
          num = num * 10 + (key - '0');
          lcd.print(key);
        }
        else if (count < 1) {
          num += (key - '0') / 10.0;
          lcd.print(key);
          count++;
        }
        break;
    }
    if (num  > 180.0) {
      lcd.clear();
      lcd.print("EXCEED MAX PARAMETER");   //The bender will bend tubing 180 degrees in one operation but not more than 180. Software limit
      delay(5000);
      software_Reset();
    }
    key = kpd.getKey();
  }
  return num;
}

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.print("JIMS MACHINE SERVICE");
  lcd.setCursor(4, 2); lcd.print("TUBING BENDER");
  lcd.setCursor(3, 3); lcd.print("COPYRIGHT  2020");
  delay(2000);
  lcd.clear();
  pinMode(CYLINDER_EXTEND, OUTPUT);
  pinMode(CYLINDER_RETRACT, OUTPUT);

  pinMode(enc_a, INPUT_PULLUP);
  pinMode(enc_b, INPUT_PULLUP);

  // start in home position
  digitalWrite(CYLINDER_EXTEND, LOW);
  digitalWrite(CYLINDER_RETRACT, HIGH);

  bendDegrees = set_Degrees();

  attachInterrupt(digitalPinToInterrupt(enc_a), encoder, FALLING);
  attachInterrupt(digitalPinToInterrupt(enc_a), encoder, FALLING);
}


void loop() {
  lcd.setCursor(0, 1); lcd.print("                "); // These two lines are to clear the screen without having a lcd.clear inside the loop?
  lcd.setCursor(4, 3); lcd.print("      ");

  float Degrees;

  noInterrupts();
  Degrees = encoderValue * .5;            //The encoder value is multiplied by .5 because the quadrature encoder doubles the value that I actually want.
  interrupts();

  lcd.setCursor(12, 3); lcd.print(Degrees, 1);

  if (Degrees < bendDegrees) {
    digitalWrite(CYLINDER_EXTEND, HIGH);    // Here the last_degrees variable, the entered value, checks with the encoder.
    digitalWrite(CYLINDER_RETRACT, LOW);
  }
  else {
    digitalWrite(CYLINDER_RETRACT, HIGH);     //send bender home after bending operation.
    digitalWrite(CYLINDER_EXTEND, LOW);
  }
}


void encoder() {
  if (digitalRead(enc_a) == digitalRead(enc_b)) {
    encoderValue++;
  }
  else {
    encoderValue--;
  }
}

Wow! I guess that I didn't scroll up to see what the IDE was telling me. I'm pretty new to C++ so honestly I'm pretty elated when I can actually get it to compile! I had a lot of different variables left in the program when I was trying to get the variable that the encoder checks against, the input degrees, to read on the display. Thank you all so much for the quick replies and I'll implement these changes. Thanks again guys. Arduino wouldn't be possible for me without all of your help.