#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 stepCount = 0; // number of steps the motor has taken
const int pinDir=10;
const int pinStep=11;
int stepsPerRevolution=12800;
int Zadanikut;
int kut;
int brojRupa;
float busenje;
String msgA="A:Odaberi kut";
String msgB="B:Odaberi broj rupa";
String msg1="Kut je =";
String msg2="Broj rupa=";
String msg3="Potvrdi sa #";
Stepper myStepper = Stepper(stepsPerRevolution,pinStep,pinDir);
#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();
lcd.setCursor(0,0);
lcd.print(msgA);
lcd.setCursor(0,1);
lcd.print(msgB);
}
void loop(){
// read the sensor value:
int sensorReading = analogRead(A0);
// map it to a range from 0 to 100:
int motorSpeed = map(sensorReading, 0, 1023, 0,100);
char key = keypad.getKey();
Serial.println(inputInt);
if (key >= '0' && key <= '9') {
lcd.print(key); // only act on numeric keys
inputString += key; // append new character to input string
}
else if (key == '#')
rio:
if (inputString.length() > 0) {
inputInt = inputString.toInt(); // YOU GOT AN INTEGER NUMBER
inputString = "";
lcd.setCursor(3,2);
lcd.print(" ");
Zadanikut=inputInt;
kut=(12800./360.)*Zadanikut;
brojRupa=inputInt;
busenje=12800./brojRupa;
}
delay(10);
if (key=='A'){
lcd.clear();
lcd.setCursor(9,0);
lcd.print(inputInt);
lcd.setCursor(3,3);
lcd.print("Pokreni sa A");
lcd.setCursor(3,2);
lcd.print(msg3);
lcd.setCursor(1,0);
lcd.print(msg1);
}
if (key=='A'){
// set the motor speed:
myStepper.setSpeed(motorSpeed);
myStepper.step(kut);
kut=-kut;
delay(10);
}
if (key == 'B'){
lcd.clear();
lcd.setCursor(3,3);
lcd.print("Pokreni sa B");
lcd.setCursor(3,2);
lcd.print(msg3);
lcd.setCursor(1,0);
lcd.print(msg2);
inputInt = 0;
}
edi:
if (key=='B'){
myStepper.setSpeed(motorSpeed);
myStepper.step(busenje);
delay(10);
key=0;
goto edi;
}
else if (key == 'C') {
lcd.clear();
inputInt = 0;// clear input
key=0;
lcd.setCursor(0,0);
lcd.print(msgA);
lcd.setCursor(0,1);
lcd.print(msgB);
inputString = 0.;
goto rio;
}
}