Subroutine problems

Hi everyone.
First of all sorry for my poor English. I hope you will understand me.

I am begginer in Arduino and I have problem with calling the subroutine programs.
When i pressed the key 1 on keypad the program normal goes to soubrutine1, but when i pressed key 2 in subroutine1 the program should go to subroutine2 and stepper should rotate, but nothing happened. Why?

In project what I am doing I need many subroutines in program.

Thanks for your help.

#include <LiquidCrystal.h> 
#include <Keypad.h> 
#include <Stepper.h> 

const byte rows = 4;
const byte cols = 4;

char keys[rows][cols] = {

byte rowPins[rows] = {5,4,3,2};
byte colPins[cols] = {27,26,25,24};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);

LiquidCrystal lcd(37, 36, 43, 42, 41, 40);  

Stepper myStepper(2048, 48,50,51,49);

void setup()
  lcd.begin(2, 16); 
  lcd.print("Stepper test"); 


void loop()

  char key = keypad.getKey();
void subroutine1()

  lcd.print("For starting"); 
  lcd.print("press key 2"); 
    char key = keypad.getKey();

void subroutine2()


subroutine2() is called in subroutuine1(). That means that you have to press key 1, and then within microseconds, press key 2. I doubt that is what you are going for.

Keypad keypad(makeKeymap(keys), rowPins, colPins, rows, cols);

With keypad in "voidloop()" I want choose which stepper I want to test: (Key1=stepper 1, key2=stepper2, key3=stepper3..) and with this I call subroutine for each stepper: (key1=subroutine1(), key2=subroutine2(),key3= subroutine3()...) each stepper has its own settings:( delay time, steps).

In this "call subroutine" i must again choose how many revolutions stepper should done. (key1= 10revolutions, key2= 50revolutions, key3= 100revolutions, key4=500revolutions...) and stepper will start rotate.

Sorry again for my poor English.


It sounds like you are trying to implement a sequential menu, as in, the first press tells you which stepper, the second tells you how many revolutions, etc. In this case, you need stop thinking in terms of subroutines and start thinking in terms of a finite state machine, with states such as CHOOSING_MOTOR, CHOOSING_STEPS, etc.