Wednesday, March 9, 2011

bugs

The program so far:-

WHAT IT DOES:

-Attaches motor 1-6 on pins 0,1,2,3,4,5
-Attaches switch 1-6 on pins 6,7,8,9,10,11

-Switch turns corresponding motor clockwise and anticlockwise 3 times
-Loop continues if switch is continuously pressed.
/////////////////////////////////////////////////////////////////////////

WHAT IT SHOULD DO BUT DOES NOT:
- Allow 2 motors to be active simultaneously
-Decrease speed both when going clockwise and anticlockwise
////////////////////////////////////////////////////////////////////////

NEXT STEPS:
-attach and program 'Formation Motors'
- fix above two problems
///////////////////////////////////////////////////////////////////////

#include <Servo.h>
#define NBR_SERVOS 6  // the number of servos

int motnum;
int beginDegree=30;
int endDegree=90;

Servo Servos[NBR_SERVOS] ; // max servos is 48 for mega, 12 for other boards

void setup()
{
  for (int i=0; i <NBR_SERVOS; i++){
  Servos[i].attach(i); // attaches 6 motors on pins 0,1,2,3,4,5
  pinMode(i+6, INPUT); //attaches swtiches on 6,7,8,9,10,11
}
}

void loop()
{
  for (int j=0; j< NBR_SERVOS; j++){
 if(digitalRead(j+6)==HIGH){
   for (int redo=0; redo<3; redo++){
  {
  for (int x=beginDegree; x<endDegree; x+=2){
    Servos[j].write(x); delay(50);
  }
  for (int y=endDegree; y<beginDegree; y-=2){
Servos[j].write(y); delay(50);
 }
 }
 }
 }
  else if (digitalRead(j+6)==LOW){
   Servos[j].write(endDegree);
 }
}
}

No comments:

Post a Comment