I'm writing a class to handle servos
the instantiation function is not being executed
the servo attached to the class does not respond
but function calls to it like Inc() and Dec() are being executed
class classServo
{
public :
classServo(int pinID);
int Angle_Get();
void Angle_Set(int intValue);
int Step_Get();
void Step_Set(int intValue);
MaxMin Range;
void Inc();
void Dec();
Servo servo;
private :
int intAngle = 0;
int intStep = 1;
};
classServo::classServo(int pinID)
{
Serial.print(" -------------- BUG -------------- THIS DOES NOT HAPPEN ---------------------");
Serial.print("classServo(): attached to pin:");
Serial.println(String(pinID));
servo.attach(pinID);
intAngle = servo.read();
}
int classServo:: Angle_Get() {
return intAngle;
}
void classServo::Angle_Set(int intValue)
{
if (intValue < Range.Min_Get())
intAngle = Range.Min_Get();
else if (intValue > Range.Max_Get())
intAngle = Range.Max_Get();
else
intAngle = intValue;
Serial.print(" Angle_Set(");
Serial.print(String(intAngle));
Serial.println(")");
servo.write(intAngle);
}
int classServo::Step_Get()
{
return intStep;
}
void classServo::Step_Set(int intValue)
{
intStep = intValue;
}
void classServo::Inc()
{
Serial.print("Inc()");
Angle_Set(Angle_Get() + intStep);
}
void classServo::Dec()
{
Serial.print("Dec()");
Angle_Set(Angle_Get() - intStep);
}
classServo sBase = classServo::classServo(pinBase);
my Serial com port reports the execution of Dec() & Angle_Set() :
Dec() Angle_Set(92)
Dec() Angle_Set(91)
Dec() Angle_Set(90)
Dec() Angle_Set(89)
Dec() Angle_Set(88)
Dec() Angle_Set(87)
Dec() Angle_Set(86)
Dec() Angle_Set(85)
Dec() Angle_Set(84)
but the
classServo::classServo(int pinID)
is not reporting anything to the Serial() port and doesn't seem to be executed.
when I connect my servo without the class it works fine but the class is failing.
any idea?