Hi all,
I want to write a new Servo Class for my project. It needs to wrap the Servo Class provided by Arduino library. It doesn't work, as there's no driving signal output. Here's my code.
I'd be appreciate if you can give a hand. ( I use Duemilanove 328, Arduino 1.0.2 IDE, on Win7)
My_ServoDriver_test.h
class My_ServoDriver_test
{
public:
My_ServoDriver_test();
My_ServoDriver_test(int portNum);
//pos: 0 -180
void setServoPosition(int pos);
public:
Servo servo;
};
My_ServoDriver_test.cpp
#include "My_ServoDriver_test.h"
My_ServoDriver_test::My_ServoDriver_test()
{
}
My_ServoDriver_test::My_ServoDriver_test(int portNum)
{
servo.attach(portNum);
}
void My_ServoDriver_test::setServoPosition(int pos)
{
servo.write(pos);
}
TestServoDriver.ino
#include <My_ServoDriver_test.h>
#include <Servo.h>
My_ServoDriver_test servoDriver(11);
void setup()
{
//Serial.begin(9600);
//servoDriver.servo.attach(11);
}
void loop()
{
servoDriver.setServoPosition(0);
delay(1000);
servoDriver.setServoPosition(180);
delay(1000);
}
If I comment the "servo.attach(portNum); " in the "My_ServoDriver_test::My_ServoDriver_test(int portNum)", and use "servoDriver.servo.attach(11);" in setup(), it works.