Hello,
I am new here and tried to search the forum, but I didnt find what I need.
I am curently working on a RC car with BT control.
I made it work with an easy code (all in loop), but I want to attach distance sensor, leds etc. so I decided to write it as objects.
Controls are simple: DC motor - forward and backward, servo - left and right.
DC motor works fine, but servo doesnt.
Here is only servo code without remote control (make it simple to explain)
#include <Servo.h>
#define SERVO_PIN 11
class Car
{
public:
Car()
: servoMotor()
{
initialize();
}
void initialize()
{
servoMotor.attach(SERVO_PIN);
}
void run()
{
servoMotor.write(45);
delay(1500);
servoMotor.write(135);
delay(1500);
}
private:
Servo servoMotor;
};
Car car;
void setup()
{
car.initialize();
}
void loop()
{
car.run();
}
Servo only moves to end position and stays there.
I am not very advanced in OOP, but this makes me sad.
Please if you could hint me what am I doing wrong, I would really appreciate it
Maros