#include <Stepper.h>
#include <Keypad.h>
//Keyboard variables
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] = { 38,37,36,35 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 42,41,40,39 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
//Stepper Variables
const int stepsPerRevolution = 60; // change this to fit the number of steps per revolution for your motor
Stepper myStepper(stepsPerRevolution, 10,11,12,13); // initialize the stepper library on pins 8 through 11:
const int time_s = 1500;
String num;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// set the speed at 60 rpm:
myStepper.setSpeed(30);
}
void loop() {
// step one revolution in one direction:
// Serial.println("clockwise");
// myStepper.step(stepsPerRevolution);
// Serial.println(stepsPerRevolution);
// delay(time_s);
// // step one revolution in the other direction:
// Serial.println("counterclockwise");
// Serial.println((-stepsPerRevolution));
// myStepper.step(-stepsPerRevolution);
// delay(time_s);
char key = keypad.getKey();
if (key != NO_KEY) {
if(isDigit(key)){
Serial.println(key);
num = num+key;
Serial.println(num);
}
if(key == '#'){
myStepper.step(atoi(num));
}
}
}