Creating an stepper object within a class

Yes, the idea is good. There are a number of ways, but since every part has exactly one stepper motor, you can put the object in the class.

A nicer way could be: 'class Finger : AccelStepper'
That way the 'AccelStepper' class is used, with your 'Finger' class as an extra. I think that 'Thumb.moveTo(90)' is nicer.

I took a look at the AccelStepper library, and it is a good, versatile and compatible class. So you can use it in every way without problems.

To distinguish the variables that are a member, they often get a underscore.

private:
  int _stepPin;
  int _dirPin;
public:
  AccelStepper _stepper;

Then you also don't need "this->" anymore.
I don't know if you need the _stepPin and _dirPin, maybe it is enough if they are in the _stepper.

1 Like