I am trying to control push button with two servo, and led. please help

#include <Servo.h>

Servo myservoa; // create first servo object to control First servo named myservoa

Servo myservob; // create second servo object to control Second servo named myservob
// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position
int inPin = 7; // choose the input pin(for a pushbutton)
int ledPin = 10; // choose the pin for the LED
int val = 0;

void setup() {
myservoa.attach(9); // attaches the servoA on pin 9 to the servo object
myservob.attach(10); // attaches the servoB on pin 10 to the servo object
pinMode(inPin,OUTPUT); // declare LED as output
pinMode(inPin,INPUT); // declare pushbutton as input
}

void loop() {

val = digitalRead(inPin);
if (val == LOW){
digitalWrite(inPin, LOW); // turn LED OFF
}

else {
digitalWrite(inPin,HIGH); // turn LED ON
if(pos =0; pos<= 180; pos+=10){ // goes from 0 degrees to 180 degrees
// in steps of 5 degrees

myservoa.write(pos); // tell servoA to go to position variable ‘pos’

delay(1500); //waits 1.5 seconds for the for servoA to reach position

myservob.write(pos); // tell servoB to go to position variable ‘pos’

}
digitalWrite(inPin,HIGH); // turn LED ON

if (pos = 180; pos >= 0; pos+=5){ // goes from 180 degrees to 0 degrees
// in steps of 5 degrees
myservob.write(pos); // tell servoB to go to position variable ‘pos’
delay(500); // waits for 1.5 seconds for the servoB to reach position
myservoA.write(pos); // tell servoA to go to position variable ‘pos’

}

explanation:

I want the

You have declared the same pin as input AND output, won't work.

pinMode(inPin,OUTPUT);    // declare LED  as output
pinMode(inPin,INPUT);     // declare pushbutton as input

Is this a duplicate of http://forum.arduino.cc/index.php?topic=396335.msg0#new

UKHeliBob:
Is this a duplicate of http://forum.arduino.cc/index.php?topic=396335.msg0#new

It was.

DO NOT CROSS-POST, CROSS-POSTING WASTES TIME.

Two duplicates deleted.

I am trying to control push button with two servo

Exactly how are the servos supposed to "control" the switch?

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html
then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Then tell us

  • what your application is?
  • what it is supposed to do?
  • what is it not doing?
  • a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks… Tom… :slight_smile:

if (pos = 180; pos >= 0; pos+=5){  // goes from 180 degrees to 0 degreesYou seem to have confused if and for as commands.