/*
* 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
*/
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Stepper.h>
const int ROW_NUM = 4; //four rows
const int COLUMN_NUM = 4; //four columns
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
char keys[ROW_NUM][COLUMN_NUM] = {
{'1','2','3', 'A'},
{'4','5','6', 'B'},
{'7','8','9', 'C'},
{'*','0','#', 'D'}
};
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
Stepper myStepper(stepsPerRevolution, 23, 25, 27, 29);
LiquidCrystal lcd(31, 33, 35, 37, 39, 41);
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
String inputString;
long inputInt;
void setup() {
myStepper.setSpeed(60); // set the speed at 60 rpm:
inputString.reserve(10); // maximum number of digit for a number is 10, change if needed
lcd.begin(16, 2); // Set up the LCD's number of columns and rows:
}
void loop() {
char key = keypad.getKey(); //Get key from Keypad
if (key) {
if (key >= '0' && key <= '9') { // only act on numeric keys
inputString += key; // append new character to input string
} else if (key == '#') { // Begin when touchin # Key
if (inputString.length() > 0) {
inputInt = inputString.toInt(); // YOU GOT AN INTEGER NUMBER
if (inputInt > 200){
myStepper.step(inputInt); // Turn back at 0 steps
inputString = ""; // Clear input
inputInt = 0; // Clear input
lcd.clear(); // Clear LCD
}
inputString = ""; // clear input
float angle = inputInt*1.8; // Variable Angle per step
lcd.print(angle); // Print To LCD
lcd.print("Grados"); // Print To LCD
myStepper.step(-inputInt-2); // Steps To Make
}
} else if (key == '*') {
myStepper.step(inputInt); // Turn back at 0 steps
inputString = ""; // Clear input
inputInt = 0; // Clear input
lcd.clear(); // Clear LCD
}
}
}