#include "AccelStepper.h"
#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd(9, 10, A2, A3, A4, A5);
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
String inputString;
long inputInt;
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {13, 12, 11, 8};
byte colPins[COLS] = {7,6,5,4};
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
int speed;
Keypad keypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup() {
stepper.setMaxSpeed(2000);
pinMode(A0,INPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
Serial.begin(9600);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("TEAM KESHARI");
lcd.setCursor(0,1);
lcd.print("CAM PROJECT");
delay(2000);
lcd.clear();
inputString.reserve(10);
}
void loop() {
char key = keypad.getKey();
if (key) {
Serial.println(key);
if (key >= '0' && key <= '9') { // 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 = ""; // clear input
// DO YOUR WORK HERE
stepper.setSpeed(inputInt);
lcd.setCursor(0,0);
lcd.print(" Speed: ");
lcd.print(inputInt/10);
stepper.runSpeed();
Serial.println(inputInt);
delay(2000);
}
} else if (key == '*') {
inputString = ""; // clear input
}
}
}