I would like to write a library for my stepper driver board using
a bunch of 74HC595 and L293.
I would like to manage (port number, speed, steps to go etc.) all motors inside
a few arrays but I cant get it work to size the array dynamical inside the constructor
of the class.
I would like to initiallize the class giving the channel count (eg. 4 * 4Bit-Pattern
connceted to 2*74HC595) etc. It should be as modular as possible to conncect
as many motors I like using shift registers etc.
I init the array _channels inside the header as follows:
class multiStepper
{
private:
int _channels[1];
byte _stepSequence[4];
int _latchPin;
int _clockPin;
int _dataPin;
int _speed;
long _previousCycle;
int _seqCounter;
int _channelCount;
public:
multiStepper(int latchPin, int clockPin, int dataPin, int channels);
void singleStep(int channel);
void begin();
void sendSequence(byte bitPattern);
void stepAll();
void refresh();
};
I init the array with one member because an empty array seems to crash the MCU.
asuryan:
I would like to manage (port number, speed, steps to go etc.) all motors inside
a few arrays but I cant get it work to size the array dynamical inside the constructor
of the class.
In what way does your code not work? What error message(s) do you get?
I inti the array with 0 so there must be 0 in both positions in the array... but there
is a 520(??) ... So it seems that the dynamic filling of the array does not work.
If it is not really clear what I mean I will make a simplified example of my problem!
So it seems that the dynamic filling of the array does not work.
Dynamically filling an array and dynamic sizing of an array are two completely different issues. The dynamic filling is working, up to the end of your static array.
If you really need dynamic sizing of the array, you will need to learn about malloc(), and all of its pitfalls.
It should be as modular as possible to conncect
as many motors I like using shift registers etc.
Really, there is going to be a practical limit to the number of motors you can power and manage. Set some reasonable upper limit (10?) and statically size the array.