Arduino Servo Library Test
Servo Test
RC Servo for steering RC cars
In RC cars, It's already integrated with RC Servo that can move from 0 to 180 degrees. But actually it can move from 45 to 120 degrees for steering the angle is fix by gears.
Sample code:
#include <Servo.h>
#define mins 45 //degree
#define maxs 120 //degree
#define center 83 //degree
//Maximum speed for turn steering 10ms
Servo myservo;
int angle = center;
bool left = true;
void setup() {
// put your setup code here, to run once:
myservo.attach(9);
}
void loop() {
// put your main code here, to run repeatedly:
myservo.write(angle);
if(left){
angle--;
}else{
angle++;
}
if(angle == mins){
left = false;
}
if(angle == maxs){
left = true;
}
delay(15);
}
This code will move the servo continuous from left to right and right to left by the limit angle of steering.
Reference: Arduino Servo

Comments
Post a Comment