Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: how can i control 4 servos but at diff times on: December 09, 2012, 12:13:40 pm
i came up with this
and right now my hand is playing marry had a little lamb (well the first part) thanks for all the help!
but i have 1 more question how can i set the mid point for one of the servos?
Code:
#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
 
int pos = 0;    // variable to store the servo position
 
void setup()
{
  myservo.attach(11);  // attaches the servo on pin 9 to the servo object
}
 
 
void loop()
{
  for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  myservo.attach(13);
  for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);    // waits 15ms for the servo to reach the position
  }
   myservo.attach(6);
  for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  myservo.attach(13);
  for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
    myservo.attach(11);
  for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
    myservo.attach(11);
  for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
    myservo.attach(11);
  for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
    myservo.attach(13);
  for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
    myservo.attach(13);
  for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
    myservo.attach(13);
  for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
      myservo.attach(11);
  for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
    myservo.attach(11);
  for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
    myservo.attach(11);
  for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}
2  Using Arduino / Project Guidance / Re: how can i control 4 servos but at diff times on: December 08, 2012, 11:41:17 am
i'm starting to think i have to restart the code
I want to make it more like the knob code but controlling 4 servos
Code:
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>

#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
 
void setup()
{
  myservo.attach(11);  // attaches the servo on pin 9 to the servo object
}
 
void loop()
{
  myservo.write(170);                  // sets the servo position according to the scaled value
  delay(1000);                           // waits for the servo to get there
  myservo.write(100);                  // sets the servo position according to the scaled value
  delay(1000);                           // waits for the servo to get there                         
}
but able to be move around the code to do diff things
3  Using Arduino / Project Guidance / Re: how can i control 4 servos but at diff times on: December 08, 2012, 08:49:24 am
A friend emailed it to me i had to change a couple things but i was never able to get them working at diff times.
4  Using Arduino / Project Guidance / Re: Maximize buzzer loudness on: December 07, 2012, 06:34:18 pm
connect it to a different bigger more powerful power source
5  Using Arduino / Project Guidance / Re: Lost my files. And now? on: December 07, 2012, 06:30:42 pm
take the hard drive out of your old computer and git it loaded on to your new computer
6  Using Arduino / Project Guidance / Re: how can i control 4 servos but at diff times on: December 07, 2012, 06:25:40 pm
hey zoomkat i tried but the board restarts the program every up load
can i do anything for that?
thanks!
7  Using Arduino / Project Guidance / Re: Reaction time Mega R3 extremely slow on: December 07, 2012, 06:22:13 pm
I need the code!
8  Using Arduino / Project Guidance / Re: how can i control 4 servos but at diff times on: December 07, 2012, 05:46:57 pm
and correct I wanted 4 servos not 5 thanks!!
 
9  Using Arduino / Project Guidance / Re: how can i control 4 servos but at diff times on: December 07, 2012, 05:38:35 pm
Code:
#include <Servo.h>

Servo myservo[5];                           
int buttonPin[] = {6, 9, 13, 11};          //pin numbers on the board for the buttons
int buttonState[] = {0, 0, 0, 0, 0};       
int lastButtonState[] = {1, 1, 1, 1, 1};
int servospeeds[] = {10, 20, 30, 40, 50};   //in milliseconds
int pos[] = {0, 0, 0, 0, 0};                //stores the next positions the servos are heading to, this is needed for the speed control
int lastPos[] = {0, 0, 0, 0, 0};
int positions[5][5] =                       //the ultimate servo destinations


  {3, 45, 90, 135, 177},       
  {177, 3, 45, 90, 135},       
  {135, 177, 3, 45, 90},       
  {90, 135, 177, 3, 45},       
  {45, 90, 135, 177, 3},         
};


void setup()
{
  int f, g;
  Serial.begin(9600);
  int x = 11;
  for (f=0; f<5; f++)
  {                                   
   myservo[f].attach(x); x--;           //pin numbers on the board for the servos
  }
  for(g = 0; g < 5; g++)
  {                                               
   pinMode (buttonPin[g], INPUT);       //sets the button pins as inputs
  }
}


void moveServo(int pp)
{
 int i, j;
 buttonState[pp] = digitalRead(buttonPin[pp]);
 if ((buttonState[pp] != lastButtonState[pp])&&(buttonState[pp] == 0))  /*if button has changed state and is now depressed*/
 {
  for(pos[i] = lastPos[i]; pos[i] <= positions[pp][i]; pos[i] ++)
  {
   for(j = 0; j < 5; j++)
   {
    myservo[j].write(pos[i]); /*i starts where it was left before and is incremented in steps of 1 degree to control the speed. I know the problem is around here, I tried to nest another for loop to increment the rows of the positions array first and then incrementing the columns, but what I get is that the servos do their things one after the other while I want them to move altogether.*/
   }
   delay(servospeeds[3]);
   lastPos[i] = pos[i];
  }
  for(pos[i] = lastPos[i]; pos[i] >= positions[pp][i]; pos[i] --)
  {
   for(j = 0; j < 5; j++)
   {
    myservo[j].write(pos[i]);
   }
   delay(servospeeds[3]);
   lastPos[i] = pos[i];
  }
 }
 lastButtonState[pp] = buttonState[pp];
}

void loop()
{
 int p;
 for (p = 0; p < 5; p++)
 {
  moveServo(p);
 }
}

I wanted to be able to rearrange the code to do diff things
10  Using Arduino / Project Guidance / Re: how can i control 4 servos but at diff times on: December 06, 2012, 05:30:14 pm
#include <Servo.h>

Servo myservo[5];                           
int buttonPin[] = {6, 9, 13, 11};          //pin numbers on the board for the buttons
int buttonState[] = {0, 0, 0, 0, 0};       
int lastButtonState[] = {1, 1, 1, 1, 1};
int servospeeds[] = {10, 20, 30, 40, 50};   //in milliseconds
int pos[] = {0, 0, 0, 0, 0};                //stores the next positions the servos are heading to, this is needed for the speed control
int lastPos[] = {0, 0, 0, 0, 0};
int positions[5][5] =                       //the ultimate servo destinations


  {3, 45, 90, 135, 177},       
  {177, 3, 45, 90, 135},       
  {135, 177, 3, 45, 90},       
  {90, 135, 177, 3, 45},       
  {45, 90, 135, 177, 3},         
};


void setup()
{
  int f, g;
  Serial.begin(9600);
  int x = 11;
  for (f=0; f<5; f++)
  {                                   
   myservo[f].attach(x); x--;           //pin numbers on the board for the servos
  }
  for(g = 0; g < 5; g++)
  {                                               
   pinMode (buttonPin[g], INPUT);       //sets the button pins as inputs
  }
}


void moveServo(int pp)
{
 int i, j;
 buttonState[pp] = digitalRead(buttonPin[pp]);
 if ((buttonState[pp] != lastButtonState[pp])&&(buttonState[pp] == 0))  /*if button has changed state and is now depressed*/
 {
  for(pos = lastPos; pos <= positions[pp]; pos ++)
  {
   for(j = 0; j < 5; j++)
   {
    myservo[j].write(pos); /*i starts where it was left before and is incremented in steps of 1 degree to control the speed. I know the problem is around here, I tried to nest another for loop to increment the rows of the positions array first and then incrementing the columns, but what I get is that the servos do their things one after the other while I want them to move altogether.*/
   }
   delay(servospeeds[3]);
   lastPos = pos;
  }
  for(pos = lastPos; pos >= positions[pp]; pos --)
  {
   for(j = 0; j < 5; j++)
   {
    myservo[j].write(pos);
   }
   delay(servospeeds[3]);
   lastPos = pos;
  }
 }
 lastButtonState[pp] = buttonState[pp];
}

void loop()
{
 int p;
 for (p = 0; p < 5; p++)
 {
  moveServo(p);
 }
}
and i am just trying to go straight from computer
11  Using Arduino / Project Guidance / how can i control 4 servos but at diff times on: December 06, 2012, 05:11:21 pm
Hi i'm trying to figure out how to control 4 servos at diff times for a robo hand that i have built and it's all working and i can get them all working at once but not at separate times.please help!
Pages: [1]