Go Down

Topic: Servo Code help (Urgent)!!!! (Read 934 times) previous topic - next topic

njkl44

Jul 06, 2010, 06:24 am Last Edit: Jul 06, 2010, 06:27 am by njkl44 Reason: 1
Alright so so far i have this code, this is for 5 servos and they have 5 flex sensor for each one. so like 1 flex sensor goes to one servo:

Code: [Select]
/*
 Servo control from an analog input
*/

int servoPin1 = 2;
int servoPin2 = 3;
int servoPin3 = 4;
int servoPin4 = 5;
int servoPin5 = 6;

int minPulse1 = 500 ;
int minPulse2 = 500 ;  
int minPulse3 = 500 ;  
int minPulse4 = 500 ;  
int minPulse5 = 500 ;  

int maxPulse1 = 4000;
int maxPulse2 = 4000;  
int maxPulse3 = 4000;  
int maxPulse4 = 4000;  
int maxPulse5 = 4000;  

int pulse1 = 0;
int pulse2 = 0;        
int pulse3 = 0;        
int pulse4 = 0;        
int pulse5 = 0;        

long lastPulse1 = 0;
long lastPulse2 = 0;    
long lastPulse3 = 0;    
long lastPulse4 = 0;    
long lastPulse5 = 0;

int refreshTime1 = 20;
int refreshTime2 = 20;
int refreshTime3 = 20;
int refreshTime4 = 20;
int refreshTime5 = 20;

 int analogPin1 = 1;
 int analogPin2 = 2;
 int analogPin3 = 3;
 int analogPin4 = 4;
 int analogPin5 = 5;

int analogValue1 = analogRead(analogPin1);
int analogValue2 = analogRead(analogPin2);
int analogValue3 = analogRead(analogPin3);
int analogValue4 = analogRead(analogPin4);
int analogValue5 = analogRead(analogPin5);

void setup() {
 pinMode(servoPin1, OUTPUT);
 pinMode(servoPin2, OUTPUT);
 pinMode(servoPin3, OUTPUT);
 pinMode(servoPin4, OUTPUT);
 pinMode(servoPin5, OUTPUT);
 pulse1 = minPulse1;  
 pulse2 = minPulse2;
 pulse3 = minPulse3;
 pulse4 = minPulse4;
 pulse5 = minPulse5;
 Serial.begin(9600);
}

void loop() {
 analogValue1 = analogRead(analogPin1);
 analogValue2 = analogRead(analogPin2);
 analogValue3 = analogRead(analogPin3);
 analogValue4 = analogRead(analogPin4);
 analogValue5 = analogRead(analogPin5);

 pulse1 = map(analogValue1,500,0 ,minPulse1,maxPulse1);
 pulse2 = map(analogValue2,500,0 ,minPulse2,maxPulse2);
 pulse3 = map(analogValue3,500,0 ,minPulse3,maxPulse3);
 pulse4 = map(analogValue4,500,0 ,minPulse4,maxPulse4);
 pulse5 = map(analogValue5,500,0 ,minPulse5,maxPulse5);
         

 
if (millis() - lastPulse1 >= refreshTime1) {
   digitalWrite(servoPin1, HIGH);  
   delayMicroseconds(pulse1);      
   digitalWrite(servoPin1, LOW);  
   lastPulse1 = millis();  
if (millis() - lastPulse2 >= refreshTime2) {
   digitalWrite(servoPin2, HIGH);  
   delayMicroseconds(pulse2);      
   digitalWrite(servoPin2, LOW);  
   lastPulse2 = millis();  
if (millis() - lastPulse3 >= refreshTime3) {
   digitalWrite(servoPin3, HIGH);  
   delayMicroseconds(pulse3);      
   digitalWrite(servoPin3, LOW);  
   lastPulse3 = millis();  
if (millis() - lastPulse4 >= refreshTime4) {
   digitalWrite(servoPin4, HIGH);  
   delayMicroseconds(pulse4);      
   digitalWrite(servoPin4, LOW);  
   lastPulse4 = millis();  
if (millis() - lastPulse5 >= refreshTime5) {
   digitalWrite(servoPin5, HIGH);  
   delayMicroseconds(pulse5);      
   digitalWrite(servoPin5, LOW);  
   lastPulse5 = millis();      
 }
}
}
}
}
}


Alright so my problem is that i only have the first servo working with the first flex sensor hen i try the other flex sensors my servo turn 180 degrees and doesnt move when i flex the sensor so im not sure whats up but any help would be awsome



I really need this fast and working soon





Thank You

nickvd

#1
Jul 06, 2010, 07:00 am Last Edit: Jul 06, 2010, 07:04 am by nickvd Reason: 1
You cross posted, check your original post for my post...


also, DON'T cross post... it angers the natives ;)

njkl44

Ya I'm sry I caught that do u want me to delete this one

mrmeval

HANG THEM with their WIRING!

BLOOD I SAY BLOOD!

Go Up