Hello everyone.
I want to arrange my code, and along with this understand object oriented programming.
I want to wrap in a library my stepper motor code.
So, in Document->Arduino->Libraries I created a dedicated folder FreeMove
Inside it I created two files, FreeMove.h and FreeMove.cpp
FreeMove.h
#ifndef FreeMove_h
#define FreeMove_h
#include "Arduino.h"
#include "AccelStepper.h"
class FreeMove {
public:
FreeMove();
void FreeMoveFunc(int StepsFreeMove);
};
#endif
FreeMove.cpp
#include "Arduino.h”
#include "FreeMove.h"
#include "AccelStepper.h"
FreeMove::FreeMove() {
}
void FreeMove::FreeMoveFunc(int StepsFreeMove){
digitalWrite(enablePin,LOW); //enables motor
stepperLevel.moveTo(StepsFreeMove);
while((stepperLevel.currentPosition() != StepsFreeMove) && ( digitalRead(liftLimitSwitchUP) == LOW)) {
stepperLevel.run();
}
digitalWrite(enablePin,HIGH); //enables motor
delay(1000);
}
The source code
#include <AccelStepper.h>
#include <FreeMove.h>
FreeMove UP();
// Define the stepper motor and the pins that is connected to
AccelStepper stepperLevel(1, 9, 10); // (Typeof driver: with 2 pins, STEP, DIR)
void setup() {
stepperLevel.setMaxSpeed(1000); // Set maximum speed value for the stepper
stepperLevel.setAcceleration(600); // Set acceleration value for the stepper
stepperLevel.setCurrentPosition(0); // Set the current position to 0 steps
}
void loop() {
UP.FreeMoveFunc(-300);
}
During compilation I got this error:
C:\Users\k\Documents\Arduino\robot_dec10\robot_dec10.ino: In function 'void loop()':
C:\Users\k\Documents\Arduino\robot_dec10\robot_dec10.ino:272:7: error: request for member 'FreeMoveFunc' in 'UP', which is of non-class type 'FreeMove()'
UP.FreeMoveFunc(300);
^~~~~~~~~~~~
exit status 1
Compilation error: request for member 'FreeMoveFunc' in 'UP', which is of non-class type 'FreeMove()'
Honestly, I'm a new at all this stuff. Please, could you help me to find what's wrong.
And any other recommendations regarding the code itself are welcome.
Many thanks in advance!