Pages: [1]   Go Down
Author Topic: Control delay between array index numbers?  (Read 395 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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);                       
}
  }
 
  
« Last Edit: March 01, 2011, 03:56:46 pm by ingi » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 634
Posts: 50245
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Like this?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 634
Posts: 50245
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: