3D scanner by brian brocken mod not working

I want to do this spinning platform for photogrametry but i dont have the joystick module, so I decided to use a LCD keypad shield instead.

I change the original code (you can find it here) to read and use the keypad instead of the joystick. It compiles and uploads fine, but i cant switch between menu´s or start a program when it starts.

Here is the modified code

I already tested the shield and the arduino (a generic Arduino UNO), and they work well.

Also the lcd screen doesn´t shine the way it should (its the software, i tried another program and the screen works good)

Can you help me?

Please post the code in line, using code tags ("</>" editor button. Also, post a complete wiring diagram.

Here is the code

#include <LiquidCrystal.h>

#include <Stepper.h>
#include <Servo.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);  // Use these pins for the LCD KPAD SHIELD
const int Kpad = A0;

int MenuNr = 0;   // Menu number
int PhotoNr = 2;  // The amount of photos that have to be taken
bool Flag1 = 0;   // This flag is only active during 1 program cycle (prevents constantly adding/subtracting 1 to the menu number when the joystick is pushed to the side) 
bool Flag2 = 0;   // This flag is only active during 1 program cycle (prevents constantly adding/subtracting 2 to the photo number when the joystick is pushed up or down)
bool Flag3 = 0;   // This flag is only active during 1 program cycle (prevents constantly adding/subtracting 1 to the RPM when the joystick is pushed up or down)
bool Flag4 = 0;   // This flag is only active during 1 program cycle (prevents constantly adding/subtracting 1 to the turn number when the joystick is pushed to the side)
bool Flag5 = 0;   // This flag is only active during 1 program cycle (prevents constantly adding/subtracting 1 to the RPM when the joystick is pushed up or down)
bool Flag6 = 0;   // This flag is only active during 1 program cycle to clear the lcd
int SwMenu = 0;   // Switch menu (Sub menu's in the main menu's)
bool BtnFlag = 0; // This flag is only active during 1 program cycle (prevents constantly adding of 1 to SwMenu when button is pressed)

int boton  = 6;     //This variable will be used to save the Kpad info
int btnRIGHT = 0;
int btnUP = 1;
int btnDOWN = 2;
int btnLEFT = 3;
int btnSELECT = 4;
int btnNONE = 5;

const int stepsPerRevolution = 2048;  // change this to fit the number of steps per revolution
int FullRev = 14336;                  // 1 full revolution of the big gear -> Small-Big gear ratio is 7:1
int rolePerMinute = 15;               // Adjustable range of 28BYJ-48 stepper is 0~17 rpm
int PhotoTaken = 0;                   // Amount of photo's that have been taken
int StepPerPhoto;                     // Amount of steps per photo (calculated -> see MenuNr 0/SwMenu 2)
int TurnNr = 1;                       // Amount of turns
int CurrentTurn = 0;                  // Stores current turn number
int Steps = 0;                        // Amount of individual steps the stepper motor has to turn

Stepper myStepper(stepsPerRevolution, 2, 11, 1, 12);  // Use these pins for the stepper motor

Servo Servo1;  // Define Servo1 as a servo

int leerKpad()  
  { boton = analogRead(0);      // Read A0
    
    // My buttons inputs:  15(right), 152(up), 337(down), 497 (left), 743 (select), and 1017 (none)
    // we compare them with some
    
    if (Kpad > 800)                 return btnNONE;     // No button pressed
    if (Kpad < 50)                  return btnRIGHT;
    if (Kpad > 100 && Kpad < 250)   return btnUP;
    if (Kpad < 400 && Kpad >250)    return btnDOWN;
    if (Kpad > 400 && Kpad < 600)   return btnLEFT;
    if (Kpad > 600 && Kpad < 800)   return btnSELECT; 

    return btnNONE;  // if something fails
  }

void setup() {
  lcd.begin(16, 2);                   //Lcd setup

  pinMode(Kpad, INPUT);             //Set pushbutton as input
  digitalWrite(Kpad, HIGH);         //Set SW_pin High
  
  myStepper.setSpeed(rolePerMinute);  //Set RPM of steppermotor

  Servo1.attach(3);                   //Attach servo to pin 3
  Servo1.write(90);                   //Move servo to mid possition

  lcd.setCursor(4, 0);                //Startup screen start
  lcd.print("Welcome!");              //      """""      //
  lcd.setCursor(1, 1);                //      """""      //
  lcd.print("Software: V1.6k");       //      """""      //
  delay(3000);                        //      """""      //
  lcd.clear();                        //      """""      //
  lcd.setCursor(0, 0);                //      """""      //
  lcd.print("Designed by");           //      """""      //
  lcd.setCursor(0, 1);                //      """""      //
  lcd.print("Brian Brocken");         //      """""      //
  delay(2000);                        //      """""      //
  lcd.clear();                        //      """""      //
  lcd.setCursor(0, 0);                //      """""      //
  lcd.print("Kpad version by");       //      """""      //
  lcd.setCursor(0, 1);                //      """""      //
  lcd.print("   Rama :)");             //      """""      //
  delay(2000);                        //      """""      //
  lcd.clear();                        //Startup screen end
}

void loop() {

 int leerKpad();

  if (MenuNr < 0){                                      //This sets the min number of menu's
    MenuNr = 0;
  }
  else if ( MenuNr > 2){                                //This sets the max numbers of menu's
    MenuNr = 2;
  }
  
  if (boton == btnRIGHT && Flag1 == 0 && SwMenu == 0){  //if right is pressed and flag1 is 0 then 1 will be added to the menu number (purpose of the flag -> see comment Flags above)
    MenuNr = MenuNr + 1; 
    Flag1 = 1;
    lcd.clear();
  }

  if (boton == btnLEFT && Flag1 == 0 && SwMenu == 0){  //if left is pressed and flag1 is 0 then 1 will be subtracted from the menu number (purpose of the flag -> see comment Flags above)
    MenuNr = MenuNr - 1;
    Flag1 = 1;
    lcd.clear();
  }
  
  if (boton == btnNONE && Flag1 == 1){          //if nothing is pressed, flag1 is set to 0 (purpose of the flag -> see comment Flags above)
    Flag1 = 0;
  }


  if (boton == btnSELECT && BtnFlag == 0){      //if the button is pressed and the flag is 0 -> add 1 to menu 
    SwMenu = SwMenu + 1;
    BtnFlag = 1;
    lcd.clear();
  }

  if (boton == btnSELECT && BtnFlag == 1){      //if the button is not pressed and the flag is 0 -> Reset the flag (purpose of the flag -> see comment Flags above)
    BtnFlag = 0;
  }
  

//*********************************************** Menu0 ***********************************************//

  if (MenuNr == 0){                             //Menu0 program

    if (SwMenu == 0){                           //Menu 0 selected
      lcd.setCursor(0, 0);
      lcd.print("Fotogrametria");
    }
  
    if (SwMenu == 1){                           //entered menu 0
      lcd.setCursor(0, 0);
      lcd.print("Nr de fotos");
      lcd.setCursor(7, 1);
      lcd.print(PhotoNr);
      
      if (boton == btnUP && Flag2 == 0){        //if up is pressed -> Add 2 to number of photo's
        PhotoNr = PhotoNr + 2;
        Flag2 = 1;
        lcd.clear();
      }
      if (boton == btnDOWN && Flag2 == 0){      //if down is pressed -> Subtract 2 from number of photo's
        PhotoNr = PhotoNr - 2;
        Flag2 = 1;
        lcd.clear();
      }
      if (boton == btnNONE && Flag2 == 1){      //if nothing is pressed -> Flag3 = 0 -> Prevents constant adding or subtracting of 2
        Flag2 = 0;
      }

      if (PhotoNr < 2){                         //Min allowable Nr of photo's
        PhotoNr = 2;
      }
      if (PhotoNr > 200){                       //Max allowable Nr of photo's
        PhotoNr = 200;
      }
    }

    if (SwMenu == 2){                           //Program started
      
      lcd.setCursor(0, 0);
      lcd.print("Iniciado");
      lcd.setCursor(0, 1);
      lcd.print("Foto Nr: ");
      lcd.print(PhotoTaken);
      
      StepPerPhoto = FullRev / PhotoNr;         //Calculate amount of steps per photo

      if (PhotoTaken < PhotoNr){          
      myStepper.setSpeed(rolePerMinute);        //Set motor speed
      myStepper.step(StepPerPhoto);             //move the calculated amount of steps
      PhotoTaken = PhotoTaken + 1;              //Add 1 to photos taken
      lcd.setCursor(0, 1);
      lcd.print("Photo Nr: ");                  //Taking photo's
      lcd.print(PhotoTaken);
      Servo1.write(30);
      delay(300);
      Servo1.write(90);
      delay(1000);
      }

      if (PhotoTaken == PhotoNr){               //If the amount of photos taken is equal to the amount of photos that have to be taken -> Program finished
        lcd.setCursor(0, 0);
        lcd.print("Finalizado");
        delay(3000);
        lcd.clear();                            //Rest parameters
        PhotoTaken = 0;
        PhotoNr = 2;
        SwMenu = 0;
        Steps = 0;
      }
    }
  }


//***********************************************Menu1***********************************************//

  if (MenuNr == 1){                            //Menu1 program
    
    if (SwMenu == 0){                          //Menu1 selected
      lcd.setCursor(0, 0);
      lcd.print("Cinematico");
    }

    if (SwMenu == 1){                          //Entered menu1 - sub menu1
      lcd.setCursor(0, 0);
      lcd.print("vel motor");
      lcd.setCursor(7, 1);
      lcd.print(rolePerMinute);

      if (boton == btnUP && Flag3 == 0){       // if up is pressed -> Add 1 RPM
        rolePerMinute = rolePerMinute + 1;
        Flag3 = 1;
        lcd.clear();
      }
      if (boton == btnDOWN && Flag3 == 0){     // if down is pressed -> Subtract 1 RPM
        rolePerMinute = rolePerMinute - 1;
        Flag3 = 1;
        lcd.clear();
      }
      if (boton == btnNONE && Flag3 == 1){     //if none is pressed -> Flag3 = 0 -> Prevents constant adding or subtracting of 1
        Flag3 = 0;
      }

      if (rolePerMinute < 1){                  //Min allowable RPM
        rolePerMinute = 1;
      }
      if (rolePerMinute > 17){                 //Max allowable RPM
        rolePerMinute = 17;
      }
    }

    if (SwMenu == 2){                          //Entered menu1 - sub menu2
      lcd.setCursor(0, 0);
      lcd.print("Nr de giros");
      lcd.setCursor(7, 1);
      lcd.print(TurnNr);

      if (boton == btnUP && Flag4 == 0){       // up is pressed -> Add 1 turn
        TurnNr = TurnNr + 1;
        Flag4 = 1;
        lcd.clear();
      }
      if (boton == btnDOWN && Flag4 == 0){     // down is pressed -> Subtract 1 turn
        TurnNr = TurnNr - 1;
        Flag4 = 1;
        lcd.clear();
      }
      if (boton == btnNONE && Flag4 == 1){     //if none is pressed -> Flag3 = 0 -> Prevents constant adding or subtracting of 1
        Flag4 = 0;
      }

      if (TurnNr < 1){                         //Min allowable amount of turns
        TurnNr = 1;
      }
      if (TurnNr > 200){                       //Max allowable amount of turns
        TurnNr = 200;
      }
    }

    if (SwMenu == 3){                          //Program started
      lcd.setCursor(0, 0);
      lcd.print("Iniciado");
      lcd.setCursor(0, 1);
      lcd.print("Giros hechos: ");
      lcd.print(CurrentTurn);

      if (CurrentTurn < TurnNr){ 
        myStepper.setSpeed(rolePerMinute);
        myStepper.step(FullRev);
        CurrentTurn = CurrentTurn + 1;
        lcd.setCursor(0, 1);
        lcd.print("Giros hechos: ");
        lcd.print(CurrentTurn);
      }

      if (CurrentTurn == TurnNr){              //If the current turn is equal to the amount of thurns that need to be turned -> program finished
        lcd.setCursor(0, 0);
        lcd.print("Finalizado");
        delay(3000);
        lcd.clear();  //Reset
        CurrentTurn = 0;
        PhotoNr = 1;
        rolePerMinute = 15;
        SwMenu = 0;
        Steps = 0;
      }
      
    }
  }

//***********************************************Menu2***********************************************//

  if (MenuNr == 2){                            //Menu2 selected
    
    if (SwMenu == 0){
      lcd.setCursor(0, 0);
      lcd.print("Control Manual");
    }

     if (SwMenu == 1){                         //Entered menu2
      lcd.setCursor(0, 0);
      lcd.print("Vel motor");
      lcd.setCursor(7, 1);
      lcd.print(rolePerMinute);

      if (boton == btnUP && Flag5 == 0){       // button up -> Add 1 RPM
        rolePerMinute = rolePerMinute + 1;
        Flag5 = 1;
        lcd.clear();
      }
      if (boton == btnDOWN && Flag5 == 0){     // button down -> Subtract 1 RPM
        rolePerMinute = rolePerMinute - 1;
        Flag5 = 1;
        lcd.clear();
      }
      if (boton == btnNONE && Flag5 == 1){     // nothing pressed -> Flag3 = 0 -> Prevents constant adding or subtracting of 1
        Flag5 = 0;
      }

      if (rolePerMinute < 1){                  //Min allowable RPM
        rolePerMinute = 1;
      }
      if (rolePerMinute > 17){                 //Max allowable RPM
        rolePerMinute = 17;
      }

      if (boton == btnRIGHT ){                 //button right and the neutral flag is 0 then 1 will be added to the menu number (purpose of the flag -> see comment Flag1 above)
        Steps = Steps + 1;
        myStepper.setSpeed(rolePerMinute);
        myStepper.step(Steps);
        lcd.setCursor(14, 1);
        lcd.print("->");
        Flag6 = 1;
      }

      if (boton == btnLEFT){                   //button left and the neutral flag is 0 then 1 will be subtracted from the menu number (purpose of the flag -> see comment Flag1 above)
        Steps = Steps + 1;
        myStepper.setSpeed(rolePerMinute);
        myStepper.step(-Steps);
        lcd.setCursor(0, 1);
        lcd.print("<-");
        Flag6 = 1;
      }

      if (boton == btnNONE) {                  //if nothing is pressed -> Flag3 = 0 -> Prevents constant adding or subtracting of 1
        Steps = 0;
        if (Flag6 == 1){
          lcd.clear();
          Flag6 = 0;                           //This flag is only active during 1 program cycle to clear the lcd
        }
      }
     }

     if (SwMenu == 2){                         //Leave menu 2 when button is pressed
       lcd.clear();
       CurrentTurn = 0;
       PhotoNr = 1;
       rolePerMinute = 15;
       SwMenu = 0;
       Steps = 0;
     }
  }
}

I couldn't found a programm to make the wiring right now (none includes the shield), but is the same as the original (This one) but with the standard pins for the shield (8 rs, 9 enable, 4, 5,6,7 their respective dr's)

Also i changed the servo to use the 3 digital pin and the stepper to the 2 digital pin (all my digital pins are pwm)

Paper and pencil work well together. Post a photo of it when you are done.

Pencil is for boomers. Here is the wiring

edit: I use only the shield instead of the board because it goes over it. The shield leaves the 1, 2, 3, 11 and 12 pins free to use, and all the keypad is to the A0 pin, so I have the rest of them for use

I already discovered why the screen wasn't shinning. I was using the 10th pin to the stepper, but this is used in the shield to control the brightness, i changed it to use the 1 pin, as i show in the wiring. So, the only problem left is why it doesn´t changes the menu's or start the programs

Looks like you are using pin 4 for your servo in your drawing.
I have an identical shield from D1 Robot, it uses pin 4 as well.
Here are my shield pin assignments:

const int8_t   lcd_d4_pin   =     4;
const int8_t   lcd_d5_pin   =     5;
const int8_t   lcd_d6_pin   =     6;
const int8_t   lcd_d7_pin   =     7;
const int8_t   lcd_RS_pin   =     8;
const int8_t   lcd_EN_pin   =     9;
const int8_t   lcd_BL_pin   =    10;
const int8_t   button_pin   =    A0;

This leaves 0 & 1 but you should probably keep those free, as well as 2, 3, 11, 12, 13, A1, A2, A3, A4, A5 free.

No, my shield have this hole which is conected to nothing, so im using 1,2 and 3 for the servo and stepper. Anyway, it shouldn't be a problem, because the screen works well, but the buttons are not working.

Try structuring your key reads in an if else tree, instead of just if statements.

I tried it, and it worked! Anyway, i also have to add a new variable to store the readed values from A0, and then use the variable i compare to the known values of the keypad (pretty dumb mistake, but well)

At least you're one step closer and you know what you're working on next. Those are two good things.

That's an odd place for a function prototype.