Great job on this library! I'm having a problem though.. changing motor.setMaxSpeed to negative or positive is not changing the direction of the motor.
Here's the code I'm converting from AccelStepper to TeensyStep..
I've only programmed the Blue and Yellow buttons so far.. pressing Blue spins the motor CCW.. then pressing Yellow also spins the motor CCW..
`#include <Adafruit_GFX.h> // Include core graphics library for the display
#include <Adafruit_SSD1306.h> // Include Adafruit_SSD1306 library to drive the display
#include <Wire.h>
#include <ResponsiveAnalogRead.h>
#include <AnalogMultiButton.h>
#include <StepControl.h>
//===============================
//button setup
//===============================
const int BUTTONS_PIN = A0; // define the analog pin for buttons
const int BUTTONS_TOTAL = 4; // button count
const int BUTTONS_VALUES[BUTTONS_TOTAL] = {12, 344, 512,614}; // assign button codes
// assign button names
const int BUTTON_BLUE = 0;
const int BUTTON_YELLOW = 1;
const int BUTTON_GREEN = 2;
const int BUTTON_RED = 3;
AnalogMultiButton buttons(BUTTONS_PIN, BUTTONS_TOTAL, BUTTONS_VALUES);
//===============================
//Pot setup
//===============================
const int knob = A9;
ResponsiveAnalogRead analog(knob,true);
int potval = 0;
Adafruit_SSD1306 display; // Create display
// Define stepper & pins.
Stepper stepper(4,3); // Define stepper & pins: motorName(step pin, direction pin)
StepControl<> controller; // Construct Controller object
int led = 13; // Built-in LED pin
int val = 0;
int StepSize = 500;
int MaxSpeed = 30000;
int MaxAccel = 200000;
int long SliderPosIn = stepper.getPosition();
int long SliderPosOut = stepper.getPosition();
int long SliderPosHome = stepper.getPosition();
int long MotorPos = stepper.getPosition();
void setup()
{
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Initialize display with the I2C address of 0x3C
Wire.setClock(1000000); // Teensy Steroid injection for the OLED
display.clearDisplay(); // Clear the buffer
display.setTextColor(WHITE); // Set color of the text
display.setRotation(0); // Set orientation. Goes from 0, 1, 2 or 3
display.setTextWrap(false); // By default, long lines of text are set to automatically “wrap” back to the leftmost column.
display.dim(0); //Set brightness (0 is maximun and 1 is a little dim)
pinMode(led, OUTPUT);
stepper.setMaxSpeed(MaxSpeed);
stepper.setAcceleration(MaxAccel);
//Serial.begin(9600);
}
void loop()
{
analog.update();
buttons.update();
potval = analog.getValue(); // Pull Analog value
if(buttons.isPressedAfter(BUTTON_BLUE,500)) // Hold Down to move
{
stepper.setMaxSpeed(-30000);
controller.rotateAsync(stepper);
while (controller.isRunning() && analogRead(BUTTONS_PIN)!=1023)
{
display.clearDisplay();
display.setFont();
display.setCursor(1,5);
display.println("Moving LEFT");
MotorPos=stepper.getPosition();
display.println(MotorPos);
display.display();
}
controller.stopAsync();
}
if(buttons.onReleaseBefore(BUTTON_BLUE,500)) // Quick click set LEFT
{
SliderPosIn = MotorPos;
display.clearDisplay();
display.setFont();
display.setCursor(1,5);
display.println("IN Point Set");
display.println(SliderPosIn);
display.display();
FlashLed(1);
}
//
if(buttons.isPressedAfter(BUTTON_YELLOW,500)) // Hold Down to move
{
stepper.setMaxSpeed(30000);
controller.rotateAsync(stepper);
while (controller.isRunning() && analogRead(BUTTONS_PIN)!=1023)
{
display.clearDisplay();
display.setFont();
display.setCursor(1,5);
display.println("Moving RIGHT");
MotorPos=stepper.getPosition();
display.println(MotorPos);
display.display();
}
controller.stopAsync(); }
//
// if(buttons.onReleaseBefore(BUTTON_YELLOW,500)) // Quick click to set
// {
// SliderPosOut = MotorPos;
// Serial.println("Right Point Set");
// FlashLed(1);
// }
//
// if(buttons.isPressed(BUTTON_RED)) // Home Motor
// {
// Serial.println("Homing");
// stepper.runToNewPosition(SliderPosHome);
// MotorPos=SliderPosHome;
// }
//
// if(buttons.onRelease(BUTTON_YELLOW)) // Run Motor IN to OUT
// {
// Serial.print("Running IN to OUT");
// stepper.runToNewPosition(SliderPosIn);
// delay(500);
// stepper.setMaxSpeed(10000);
// stepper.setAcceleration(5000);
// FlashLed(2);
// stepper.runToNewPosition(SliderPosOut);
// Serial.println("....Done");
// stepper.setMaxSpeed(MaxSpeed);
// stepper.setAcceleration(MaxAccel);
// MotorPos=SliderPosHome;
// FlashLed(3);
//
//
// }
// if(analog.hasChanged())
// {
// StepSize = map(potval,2,999,5,1000); // remap pot to StepSize
//// stepper.runToNewPosition(MotorPos);
// FlashLed(1);
// }
}
void FlashLed(int blinks)
{
digitalWrite(led,LOW);
for (int x = 1; x<= blinks; x++) {
digitalWrite(led,HIGH);
delay(100);
digitalWrite(led,LOW);
delay(100);
}
}
`