Every time I try to set a variable for one motor in a motorInfo class I’ve defined it updates info for all of the instances of the class.
Here is some of the code from the .ino
#include "motorInfo.h"
#include "application.h"
#include "math.h"
// This #include statement was automatically added by the Particle IDE.
#include "Adafruit-MotorShield-V2/Adafruit-MotorShield-V2.h"
// Create the motor shield object with the default I2C address
#include <stdarg.h>
#define PRINTF_BUFFER_SIZE 128
#define MOTORS 6
#define SHIELD_COUNT 3
int i =0;
Adafruit_MotorShield afms[SHIELD_COUNT];
Adafruit_StepperMotor *steppers[MOTORS];
motorInfo *info[MOTORS];
void Serial_printf(const char* fmt, ...) {
char buff[PRINTF_BUFFER_SIZE];
va_list args;
va_start(args, fmt);
vsnprintf(buff, PRINTF_BUFFER_SIZE, fmt, args);
va_end(args);
Serial.println(buff);
}
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Stepper test!");
for(i = 0;i<SHIELD_COUNT;i++){
String shieldNum = "0x6" + i;
String endTest = "";
afms[i] = Adafruit_MotorShield(0x60+i);
//afms[i] = Adafruit_MotorShield(0x6+i);
afms[i].begin();
}
/****this is the line that sets all of the motor info instances to have 45 steps *******/
info[4]->setSteps(45);
for(i = 0;i<MOTORS;i++){
int f = floor(i/2);
steppers[i] = afms[f].getStepper(200, ((i%2)+1));
steppers[i]->setSpeed(255);
info[i] = new motorInfo;
Serial.print("Motor : ");
Serial.println(i);
Serial.print(" State : ");
Serial.println(info[i]->getState() );
Serial.print(" Direction : ");
Serial.println(info[i]->getDirection());
Serial.print(" Style : ");
Serial.println(info[i]->getStyle());
Serial.print(" Steps : ");
Serial.println(info[i]->getSteps());
Serial_printf("address of motor info %d is %x", i, info[i]);
Serial.println();
delay(1000);
}
}
I’ve ensured that the pointers are referencing different addresses in the particle cli ie but still all of the instances have 45 steps even though I only specified info[4] to have 45 steps.
Motor : 2
State : 0
Direction : 68
Style : 69
Steps : 45
address of motor info 2 is 20005368
Motor : 3
State : 0
Direction : 68
Style : 69
Steps : 45
address of motor info 3 is 20005358
Motor : 4
State : 0
Direction : 68
Style : 69
Steps : 45
address of motor info 4 is 20005490
Motor : 5
State : 0
Direction : 68
Style : 69
Steps : 45
address of motor info 5 is 20005458
here is the motorInfo.h file
#include "application.h"
#ifndef motorInfo_h
#define motorInfo_h
class motorInfo {
public:
motorInfo();
void
setState(bool state),
setSteps(int steps),
setDirection(uint8_t direction),
setStyle(uint8_t style);
int
getSteps(void);
bool
getState(void);
uint8_t
getDirection(void),
getStyle(void);
private:
};
#endif // motorInfo.h
and also the motorInfo.cpp
#include "motorInfo.h"
bool myState = false;
int mySteps = 0;
uint8_t myDirection = 'FORWARD';
uint8_t myStyle = 'SINGLE';
motorInfo::motorInfo(){
}
void motorInfo::setState(bool state){
myState = state;
}
void motorInfo::setSteps(int steps){
mySteps = steps;
}
void motorInfo::setDirection(uint8_t direction){
myDirection = direction;
}
void motorInfo::setStyle(uint8_t style){
myStyle = style;
}
int motorInfo::getSteps(){
return mySteps;
}
bool motorInfo::getState(){
return myState;
}
uint8_t motorInfo::getDirection(){
return myDirection;
}
uint8_t motorInfo::getStyle(){
return myStyle;
}
it seems simple enough but maybe I’m just missing something here. Any and all help would be much appreciated.
best
p