Go Down

Topic: Control delay between array index numbers? (Read 416 times) previous topic - next topic

ingi

Mar 01, 2011, 09:26 pm Last Edit: Mar 01, 2011, 09:56 pm by ingi Reason: 1
Hello, I am making a small code for arduino where I controle servos with array. What I am trying to find out is to control how long it will take myservo 1 for example to travel from index 2 to 3.  I would like to do that with int del1. If you could point me tovards some answere would be great.
Hope this makes sence

Best

Ingirafn

Code: [Select]
#include <Servo.h>

Servo myservo1;
Servo myservo2; 

int serv1[] = {10, 10, 20, 20, 10};
int serv2[] = {10, 20, 20, 10, 10};
int del1[] = {10, 10, 20, 20, 10}; // i imagien i would use this to contol different "delays".

int pos ;
int pause = 150;
int times = 4;
void setup()
{
  myservo1.attach(10);
  myservo2.attach(9); 
}


void loop()
{
  for(int i=0; i<times; i=i+1)
{                                 
myservo1.write(serv1[i]); // here i would try to control how fast it will jump from one stepp to the other (one index to another in "myserv1 and 2", //preferably as a array also.

myservo2.write(serv2[i]);
    delay(pause);                       
}
  }

 
 

PaulS

The forum software does not like the string of characters [ i ] in quotes or plain text. It thinks they are a tag to start displaying italics. Please modify your post, to delete the code. Press the # button above the text entry block, and paste your code again.

As it is, it is impossible to tell what that code is supposed to be doing.

ingi


PaulS

Yes, that is much better. Replace the value that is in the () after for the delay statement with the del1 array element:
Code: [Select]
delay[del1[i]);

Go Up