Need some help, when the A3 phaser is pushed to the highest, the maximum speed of the motor reaches the limit, is there a way to break through the maximum speed? thank you so much! ( I have tried to change the maximum speed and acceleration value, but it does not work)
#include <AccelStepper.h>
#include "Arduino.h"
#include "LiquidCrystal.h"
#include "Button.h"
// Pin Definitions
#define LCD_PIN_RS 8
#define LCD_PIN_E 7
#define LCD_PIN_DB4 3
#define LCD_PIN_DB5 4
#define LCD_PIN_DB6 5
#define LCD_PIN_DB7 6
#define PUSHBUTTON_PIN_2 9
#define STEPPER_PIN_STEP 11
#define STEPPER_PIN_DIR 10
#define POTENTIOMETERSLIDE_5V_PIN_WIPER A3
// Global variables and objects
LiquidCrystal lcd(LCD_PIN_RS, LCD_PIN_E, LCD_PIN_DB4, LCD_PIN_DB5, LCD_PIN_DB6, LCD_PIN_DB7);
Button pushButton(PUSHBUTTON_PIN_2);
AccelStepper stepper(AccelStepper::DRIVER, STEPPER_PIN_STEP, STEPPER_PIN_DIR);
int speed = 0;
// Constants
#define STEPPER_ACCELERATION 3000
#define STEPPER_MAX_SPEED 500
#define STEPPER_MIN_SPEED 0
#define STEPPER_CONTROL_INTERVAL 0.01
// Variables
bool motorRunning = false;
bool buttonState = false;
bool buttonPreviousState = false;
unsigned long previousControlTime = 0;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
stepper.setMaxSpeed(STEPPER_MAX_SPEED);
stepper.setAcceleration(STEPPER_ACCELERATION);
lcd.setCursor(0, 0);
lcd.print("Speed: 0 RPM");
}
void loop() {
buttonState = pushButton.read();
if (buttonState != buttonPreviousState) {
if (buttonState) {
if (!motorRunning) {
stepper.setSpeed(0);
stepper.enableOutputs();
motorRunning = true;
lcd.setCursor(0, 1);
lcd.print("Motor Running ");
} else {
stepper.disableOutputs();
motorRunning = false;
lcd.setCursor(0, 1);
lcd.print("Motor Stopped ");
}
}
}
buttonPreviousState = buttonState;
if (motorRunning) {
unsigned long currentMillis = millis();
if (currentMillis - previousControlTime >= STEPPER_CONTROL_INTERVAL) {
int potentiometerValue = analogRead(POTENTIOMETERSLIDE_5V_PIN_WIPER);
int speed = map(potentiometerValue, 0, 1023, STEPPER_MIN_SPEED, STEPPER_MAX_SPEED);
if (speed != stepper.speed()) {
stepper.setSpeed(speed);
lcd.setCursor(7, 0);
lcd.print(speed);
lcd.print(" RPM ");
}
stepper.runSpeed();
previousControlTime = currentMillis;
}
}
}