The code that follows compiles just fine on the old IDE, but on the new IDE 2.32, it gets the following error. It doesn't seem to recognize the delayMicroseconds command.
This is the error:
C:\Users\Mike\Desktop\T4DualStep\stepClass.cpp: In member function 'void StepperClass::enable()':
C:\Users\Mike\Desktop\T4DualStep\stepClass.cpp:21:1: error: 'delayMicros' was not declared in this scope; did you mean 'elapsedMicros'?
exit status 1
Compilation error: exit status 1
I downloaded the new IDE2.3.2 but that didn't help.
Why would it compile under the old IDE but not the new one?
This is the T4DualStep.ino file:
#include "arduino.h"
const int ENABLE1 = 8;
const int DIRECTION1 = 5;
const int STEP1 = 2;
const int ENABLE2 = 8;
const int DIRECTION2 = 6;
const int STEP2 = 3;
const int MAX_SPEED = 1000; // maximum requested motor speed control
const int MAX_ACCELERATION = 5000; // acceleratiom of the motor speed
const int TESTSPEED = 50;
float targetSpeed = 0; // target motor speed
float adjustedSpeed = 0; // adjusted motor speed
float actualSpeed = 0; // actual real time speed of motor
float timerPeriod;
unsigned long loopNow, loopLast; // loop time
unsigned long reverseNow, reverseLast; // direction reverse time
volatile int8_t motorDirection1 = 1; // direction of stepper motor 1 = CW, -1 = CCW, 0 = stopped
volatile int8_t motorDirection2 = 1; // direction of stepper motor 1 = CW, -1 = CCW, 0 = stopped
int spd = TESTSPEED;
IntervalTimer pulseTimer; // create a motor pulse timer
/**************************************************************************************************************/
void setup() {
Serial.begin(115200); // start the Serial communications
delay(500);
Serial.println("Hi");
// set up the A4988 carrier pins
pinMode(ENABLE1, OUTPUT); // Arduino digital pin (Active LOW)
pinMode(STEP1, OUTPUT); // Arduino digital pin
pinMode(DIRECTION1, OUTPUT); // Arduino digital pin
pinMode(ENABLE2, OUTPUT); // Arduino digital pin (Active LOW)
pinMode(STEP2, OUTPUT); // Arduino digital pin
pinMode(DIRECTION2, OUTPUT); // Arduino digital pin
digitalWrite(ENABLE1, HIGH); // disable the stepper
digitalWrite(STEP1, HIGH);
digitalWrite(DIRECTION1, HIGH);
digitalWrite(ENABLE2, HIGH); // disable the stepper
digitalWrite(STEP2, HIGH);
digitalWrite(DIRECTION2, HIGH);
pulseTimer.priority(0);
motorDirection1 = 1; // motor direction = CW
motorDirection2 = 1; // motor direction = CW
digitalWrite(ENABLE1, LOW); // Enable the stepper
digitalWrite(ENABLE2, LOW); // Enable the stepper
loopLast = millis();
reverseLast = millis();
}
/**************************************************************************************************************/
void loop() {
loopNow = millis();
if (loopNow - loopLast >= 5) // 5ms loop
{
// SetMotorSpeed1(spd);
// SetMotorSpeed2(spd);
loopLast = loopNow;
}
reverseNow = millis();
if (reverseNow - reverseLast >= 1000) // 1000ms loop
{
reverseLast = reverseNow;
if (spd == TESTSPEED)
spd = -TESTSPEED;
else
spd = TESTSPEED;
// Serial.println(spd);
}
}
This is the stepperClass.h file:
#ifndef __StepperClass_H__
#define __StepperClass_H__
class StepperClass {
private:
int _enable;
int _step;
int _direction;
int _speed;
int _position;
int _target;
public:
StepperClass(int enable, int step, int direction, int stepsPerRev); // constructor
void changeDirection(); // reverse the current dorection (any mode)
void enable(); // enable the stepper
void disable(); // disable the stepper
int getPosition(); // get the stepper's current position (async or sync mode)
int getTarget(); // get the stepper's target location (async or sync mode)
int getSpeed(); // get the current speed (any mode)
void moveToTarget(); // does the actual move (async or sync mode)
void step(); // step the stepper one step
void setAsyncMode(); // steppers arrive independently
void setContinuousMode(); // setSpeed causes a continuoue move in selected direction
void setForward(); // move the stepper forward (any mode)
void setPosition(); // set the stepper's current position (async or sync mode)
void setReverse(); // move the stepper reverse (any mode)
void setSpeed(); // set the desired speed of movement (any mode))
void setSyncMode(); // steppers arrive at the same time regardless of distance moved
void setTarget(); // set the stepper's target location (async or sync mode)
};
#endif
Here is the stepperClass.cpp file:
#include "arduino.h"
#include "stepperClass.h"
/**************************************************************************************************************/
StepperClass::StepperClass(int enable, int step, int direction, int stepsPerRev) { // constructor
_enable = enable;
_step = step;
_direction = direction;
_speed = 0;
_position = 0;
_target = 0;
}
/**************************************************************************************************************/
void StepperClass::changeDirection() {
digitalWrite(_direction, !digitalRead(_direction)); // reverse the current direction (any mode)
}
/**************************************************************************************************************/
void StepperClass::enable() { // enable the stepper
digitalWrite(_step, LOW);
delayMicroseconds(1);
digitalWrite(_step, HIGH);
}
/**************************************************************************************************************/
void StepperClass::disable() { // disable the stepper
}
/**************************************************************************************************************/
int StepperClass::getPosition() { // get the stepper's current position (async or sync mode)
return _position;
}
/**************************************************************************************************************/
int StepperClass::getTarget() { // get the stepper's target location (async or sync mode)
return _target;
}
/**************************************************************************************************************/
int StepperClass::getSpeed() { // get the current speed (any mode)
return _speed;
}
/**************************************************************************************************************/
void StepperClass::moveToTarget() { // does the actual move (async or sync mode)
}
/**************************************************************************************************************/
void StepperClass::step() { // step the stepper one step
}
/**************************************************************************************************************/
void StepperClass::setAsyncMode() { // steppers arrive independently
}
/**************************************************************************************************************/
void StepperClass::setContinuousMode() { // setSpeed causes a continuoue move in selected direction
}
/**************************************************************************************************************/
void setForward() { // move the stepper forward (any mode)
}
/**************************************************************************************************************/
void StepperClass::setPosition() { // set the stepper's current position (async or sync mode)
}
/**************************************************************************************************************/
void StepperClass::setReverse() { // move the stepper reverse (any mode)
}
/**************************************************************************************************************/
void StepperClass::setSpeed() { // set the desired speed of movement (any mode))
}
/**************************************************************************************************************/
void StepperClass::setSyncMode() { // steppers arrive at the same time regardless of distance moved
}
/**************************************************************************************************************/
void StepperClass::setTarget() { // set the stepper's target location (async or sync mode)
}