#include <Keypad.h>

const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
  { '1', '2', '3', 'A' },
  { '4', '5', '6', 'B' },
  { '7', '8', '9', 'C' },
  { '*', '0', '#', 'D' }
};

uint8_t colPins[COLS] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 }; // Pins connected to R1, R2, R3, R4

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

#include <Stepper.h>
 int stepsPerRevolution=200;
 int motSpeed=10;
 int dt=500;
 int j;
 int Zadanikut;
 int kut=200;
 int brojRupa;
 int busenje;
 String msg="A:Odaberi kut";
 String msg1="B:Odaberi broj rupa";
 String msgA="Koliki je kut?";
 String msgB="Koliko rupa :";
 String msgC="Za nastavak X ";
 String odgovor;
 char odgovor1;
 
 Stepper myStepper = Stepper(stepsPerRevolution, 10,11,12,13);

 #include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 20, 4);


/*
 * Created by ArduinoGetStarted.com
 *
 * This example code is in the public domain
 *
 * Tutorial page: https://arduinogetstarted.com/faq/how-to-input-a-multiple-digits-number-using-the-keypad
 */



String inputString;
int inputInt;

void setup() {
  Serial.begin(9600);
  inputString.reserve(10); // maximum number of digit for a number is 10, change if needed
  lcd.init();
  lcd.backlight();
   myStepper.setSpeed(60);
}

void loop() {
  char key = keypad.getKey();

  if (key) {
    Serial.println(key);
    

    if (key >= '0' && key <= '9') {
      
        lcd.print(key);  // only act on numeric keys
      inputString += key;               // append new character to input string
    } else if (key == '#') {
      if (inputString.length() > 0) {
        inputInt = inputString.toInt(); // YOU GOT AN INTEGER NUMBER
        inputString = "";
        Serial.print(inputInt);
         lcd.clear();
         lcd.setCursor(2, 0);
         lcd.print("Kut je:");
        lcd.print(inputInt);               // clear input
        // DO YOUR WORK HERE
        
           Zadanikut=inputInt;
         
        kut=(200./360.)*Zadanikut;
        myStepper.step(kut);
        delay(500);
        kut=-kut;
        myStepper.step(kut);
        delay(500);
        
      }
    } else if (key == '*') {
      inputString = ""; 
                      // clear input
    }
  }
}