#include <Stepper.h>
const int stepsPerRevolution = 200; // Change this based on your stepper motor specifications
char prevInputB= 1;
char prevInputA = 'a';
Stepper columnStepper(stepsPerRevolution, 8, 9, 10, 11);
Stepper rowStepper(stepsPerRevolution, 4, 5, 6, 7);
// Function to move the stepper motors based on chess coordinates with a constant speed
void moveToPosition(char column, int row) {
// Set the speed for column stepper motor
columnStepper.setSpeed(200);
// Convert column character to a corresponding number (A=1, B=2, ..., H=8)
// Move the column stepper motor
int columnSteps = (column ) * stepsPerRevolution;
columnStepper.step(columnSteps*10);
// Set the speed for row stepper motor
rowStepper.setSpeed(200);
// Move the row stepper motor
int rowSteps = (row ) * stepsPerRevolution;
rowStepper.step(rowSteps*10);
}
void setup() {
Serial.begin(9600); // Initialize serial communication at 9600 bps
}
void loop() {
char column;
int row;
Serial.println("Enter chess move (e.g., E5):");
// Check if there's serial data available
while (Serial.available() < 2) {
// Wait for user input
}
if (Serial.available() > 0) {
// Read the input string until a newline character is received
String input = Serial.readStringUntil('\n');
// Parse the input string (assuming format like "A5")
sscanf(input.c_str(), "%c%d", &column, &row);
column = tolower(column);
// Move to the specified position
Serial.print("Received Move: ");
Serial.print(column);
Serial.println(row);
}
int rotationsA = column - prevInputA; // Calculate the difference
int rotationsB= row - prevInputB;
int forprintB= prevInputB;
Serial.print("Previous COLUMN Position: ");
Serial.println(prevInputA);
Serial.print("Column Rotations: ");
Serial.println(rotationsA);
Serial.print("Previous ROW Position: ");
Serial.println(forprintB);
Serial.print(" Row Rotations: ");
Serial.println(rotationsB);
moveToPosition(rotationsA, rotationsB);
prevInputB = row;
prevInputA = column;
}