// Include necessary libraries
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <ArduinoJson.h>
// Define stepper motor pins
#define STEP_PIN 18
#define DIR_PIN 9
#define ENABLE_PIN 15
void setup() {
// Set stepper motor pins as outputs
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
pinMode(ENABLE_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
// Rotate stepper motor clockwise
rotateStepper(200, HIGH);
delay(1000); // Delay for demonstration
// Rotate stepper motor counterclockwise
rotateStepper(200, LOW);
delay(1000); // Delay for demonstration
}
void rotateStepper(int steps, int direction) {
// Enable the stepper driver
digitalWrite(ENABLE_PIN, LOW);
// Set the direction
digitalWrite(DIR_PIN, direction);
// Rotate the motor
for (int i = 0; i < steps; i++) {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(500); // Adjust delay as needed
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(500); // Adjust delay as needed
}
// Disable the stepper driver to save power
digitalWrite(ENABLE_PIN, HIGH);
}