Tuesday, 30 November 2010

#include <Servo.h>
Servo myservo;  // declares servo
Servo myservo2;
Servo myservo3;
int pos = 0;

int inputPin1l = 1; // assigns input (button) to pin number
int inputPin1r = 2;
int inputPin2l = 3;
int inputPin2r = 4;
int inputPin3l = 5;
int inputPin3r = 6;
int val1l = 0;
int val1r = 0;
int val2l = 0;
int val2r = 0;
int val3l = 0;
int val3r = 0;


void setup() {
  myservo.attach(9);          //assigns servo to pin number
  myservo2.attach(10);
  myservo3.attach(11);   
pinMode (inputPin1l, INPUT);    // declares button as input
pinMode (inputPin1r, INPUT);
pinMode (inputPin2l, INPUT);
pinMode (inputPin2r, INPUT);
pinMode (inputPin3l, INPUT);
pinMode (inputPin3r, INPUT);
}

void loop()  {
  val1l = digitalRead(inputPin1l);
  val1r = digitalRead(inputPin1r);
  val2l = digitalRead(inputPin2l);
  val2r = digitalRead(inputPin2r);
  val3l = digitalRead(inputPin3l);
  val3r = digitalRead(inputPin3r);

  if (val1l == LOW) {                        //if input (button value is 0
    for(pos = 0; pos < 180; pos += 1);     // this will happen
 {
   myservo.write(pos);
   delay(3);
 }
 for(pos = 180; pos>=1; pos-=1)
 {
   myservo.write(pos);
   delay(3);
 }

  }

 else if( val1r == LOW ) {
  for(pos = 0; pos < 180; pos += 1);     // this will happen
 {
   myservo.write(pos);
   delay(3);
 }
 for(pos = 180; pos>=1; pos-=1)
 {
   myservo.write(pos);
   delay(3);
 }

}

else if( val2l == LOW ) {
  for(pos = 0; pos < 180; pos += 1);     // this will happen
 {
   myservo2.write(pos);
   delay(3);
 }
 for(pos = 180; pos>=1; pos-=1)
 {
   myservo2.write(pos);
   delay(3);
 }

}

else if( val2r == LOW ) {
  for(pos = 0; pos < 180; pos += 1);     // this will happen
 {
   myservo2.write(pos);
   delay(3);
 }
 for(pos = 180; pos>=1; pos-=1)
 {
   myservo2.write(pos);
   delay(3);
 }

}

else if( val3l == LOW ) {
  for(pos = 0; pos < 180; pos += 1);     // this will happen
 {
   myservo2.write(pos);
   delay(3);
 }
 for(pos = 180; pos>=1; pos-=1)
 {
   myservo2.write(pos);
   delay(3);
 }

}

else if( val3r == LOW ) {
  for(pos = 0; pos < 180; pos += 1);     // this will happen
 {
   myservo3.write(pos);
   delay(3);
 }
 for(pos = 180; pos>=1; pos-=1)
 {
   myservo3.write(pos);
   delay(3);
 }

}

}

No comments:

Post a Comment