04 SmartRobotCarV4.0 ServoControl
04 SmartRobotCarV4.0 ServoControl
Introduction:
In this lesson, we will teach you how to control the servo of the Smart
Robot Car.
Preparation:
A Smart Robot Car (with battery)
A USB Wire
As shown in the picture, servo can be connected to the pin D10 or pin
D11 of the UNO.
And the control of the servo is also relatively simple. After adding the
official library, you can modify the angle to control it at will.
// in DeviceDriverSet_xxx0.h
/*Servo*/
#include <Servo.h>
class DeviceDriverSet_Servo
{
public:
void DeviceDriverSet_Servo_Init(unsigned int Position_angle);
#if _Test_DeviceDriverSet
void DeviceDriverSet_Servo_Test(void);
#endif
void DeviceDriverSet_Servo_control(unsigned int Position_angle);
private:
#define PIN_Servo_z 10
};
uint8_t attach(int pin, int min, int max) as above but also sets min and max values for writes
// in DeviceDriverSet_xxx0.cpp
And then choose the servo you need according to the rotation angles
of the servo.
// in DeviceDriverSet_xxx0.cpp
/*0.17sec/60degree(4.8v)*/
void DeviceDriverSet_Servo::DeviceDriverSet_Servo_control
(unsigned int Position_angle)
{
myservo.attach(PIN_Servo_z);
myservo.write(Position_angle);
delay(450);
myservo.detach();
}
http://www.elegoo.com