#include <Servo.h> // import servo control functions
Servo myservo1;
Servo myservo2;
int currentValue = 0;
int targetValue = 0;
int angleValue = 50;
void setup() {
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
//Serial.begin(9600);
myservo1.attach(9);
myservo2.attach(10);
}
void loop() {
/////////////////////////////////////////////////////////////////////////
//CALCULATE THE FINAL ANGLE
targetValue = digitalRead(5)*angleValue + digitalRead(6)*angleValue + digitalRead(7)*angleValue + 20;
/*
if(digitalRead(5)==HIGH) {
targetValue = 90;
} else if(digitalRead(5)==LOW) {
targetValue = 0;
}
*/
/////////////////////////////////////////////////////////////////////////
//DECIDE + OR -
if(currentValue<targetValue) {
currentValue = currentValue + 1;
} else if(currentValue>targetValue) {
currentValue = currentValue - 1;
}
/////////////////////////////////////////////////////////////////////////
//CHECK VALUE
// Serial.println(currentValue);
/////////////////////////////////////////////////////////////////////////
//SEND VALUE TO MOTOR
myservo1.write(currentValue);
myservo2.write(170-currentValue);
///////////////////////////////////////////////////////////////////////////
//MAKE IT NOT TOO FAST
delay(50);
}
But there is some problem that two motor can not start at the same time. It could be the problem of motor because when it is close to 0 or 179 degree, it is not accurate. We will try to use program to control it since we have already built everything.
No comments:
Post a Comment