Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / problem with array code for servo on: March 10, 2011, 08:37:14 pm
Hello, I have posted few questions about my code im working on and still I need help. I have this code where I want to controle two servo motors with array index. I want to be able to controle the time ther servo motor takes to go from one index nr to the other. I post the code here.

Code:


#include <Servo.h>
 
Servo servox;
Servo servoy; 


int movex[] = {16, 48, 135, 180};
int movey[] = {10, 20, 30, 40};
int de[] = {10, 200, 4000, 80000};
int fmovex = 0;

void setup()
{
  Serial.begin(9600);
  servox.attach(10);
  servoy.attach(9);
}

 void loop() {
 
   for(int i=0; i<4; i=i+1){
 int (movex[i] = (fmovex));
if (movex[i]<movey[i+1]);fmovex++;   //here I would like the fmovex to "count down" from array index 1 to 2, and then 2 to 3 and so on. But it begins //not on 16 but on 0 and then down to 180 or where the rotation comes to its end. Does this make any sence?

Serial.println (fmovex);
servox.write(fmovex);
delay (de[1]);
}
  }
 
2  Using Arduino / Programming Questions / Re: smiple "calcuation" problem? on: March 04, 2011, 07:00:52 pm
 smiley
Yes, so simple. Thanks.
 smiley
3  Using Arduino / Programming Questions / smiple "calcuation" problem? on: March 02, 2011, 09:29:18 pm
Hello, i am working on a simpe servo code using array. Here is a small part of the code, I hope it does not matter that it is not full yet. I have the "variables" (is that the right name?) "nr1" and "nr2". The "nr2" has to be one digit higher than "nr1".  See bellow.

Code:
#include <Servo.h>
 
Servo myservo1;
Servo myservo2; 


int blikk1[] = {100, 10, 120, 10};
int nr1 = 0;   
int nr2 = 0;
int stad1 = 0;                                 
int blikk2 =0;
void setup() {
Serial.begin(9600); 
}
 
 
void loop() {
 for(int i=0; i<4; i=i+1){

   
nr1 = blikk1[i];
nr2 = blikk2[i]++1; //this is my problem. I want the "nr2" to be one digit higher than the "nr1". I guess you can see how Im trying to do this.


Any sugestion would be appreciated.

Best

Ingirafn
4  Using Arduino / Programming Questions / Re: Control delay between array index numbers? on: March 01, 2011, 03:57:01 pm
Like this?
5  Using Arduino / Programming Questions / Control delay between array index numbers? on: March 01, 2011, 03:26:31 pm
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);                       
}
  }
 
  
6  Using Arduino / Programming Questions / problem with a sweep and array schetch. on: February 01, 2011, 04:01:56 pm
Hello, I have been putting togeather a code from the "examples/servo/sweep" schetch which comes with the Arduino Software and a "array" schetch I found somewhere. It is now working but there is one small thing I cant figure out. In the orginal "sweep" schetch I can controle how many "steps" the servo motor connected to the board takes. But I cant make it happend in the code I have cooked up. First I show you the orginal "sweep" schetch and then the one i have cooked. What do I do wrong?

Best

Ingirafn

Sweep schetch.

// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.

#include <Servo.h>
 
Servo myservo; 
 
int pos = 0;   
 
void setup()
{
  myservo.attach(9);   
}
 
 
void loop()
{
  for(pos = 30; pos < 70; pos += 1)   //Here I belive it the code that makes it take one step at a time "pos +=1"
  {                                 
    myservo.write(pos);             
    delay(200);                     
  }
  for(pos = 70; pos>=30; pos-=1)     
  {                               
    myservo.write(pos);             
    delay(200);                       
  }
}


My schetch.

#include <Servo.h>
 
Servo myservo1;
Servo myservo2; 

int pointx[] = {50, 10, 50, 90, 50};
int pointy[] = {10, 50, 90, 50, 10};
int pos = 0;                                 

void setup()
{
  myservo1.attach(10);
  myservo2.attach(9); 
}
 
 void loop()
{
  for(int i=0; i<6; i=i+1)
{                                 
 myservo1.write(pointx);//pos+= 10; //Here I am trying to control how many steps the servo will take before delay.
delay(100);

}
  for(int i=0; i<6; i=i+1)
{
myservo2.write(pointy); //pos += 10;
delay(100);                       
}
}
 
7  Forum 2005-2010 (read only) / Frequently-Asked Questions / "stop" or "reset" button on: August 25, 2010, 04:06:18 am
Hello, I was wondering if anyone can help me with a simple matter. I have just bought a arduino duemilanoe atmega 328 board. I have loaded it with the simple "servo swep" from "exmples". How do I make it stop? I have pushed the stop button in the software and the reset button on the hardware it self. But it just continues running. Im sure I missed something in the "how to" section and at this moment  I am not finding it.

Best

Ingi
Pages: [1]