NAND gate code help

M1 & M2 are servo motors 1 & 2
A & B are the orientation detection (with the help of switches)
Activity is the output of the gate operation which further rotates the servos

M1 M2 O/P Activity
B(ON) A(OFF) HIGH M1 (rotates) then M2 (rotates)
B(ON) B(ON) LOW M1 & M2 (no rotation)
A(OFF) A(OFF) HIGH M1(rotates) then M2 (rotates)
A(OFF) B(ON) HIGH M2 (rotates) then M1 (rotates)

here is the code I have written for just one output(I would like to know if my approach is right):

#include <Servo.h> 
 
Servo servo1; 
Servo servo2;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0; 
void setup(){
  
  servo1.attach(9);  // attaches the servo on pin 9 to the servo object 
  servo2.attach(10);

  // declaration of pin modes
  pinMode(pinx, INPUT);
  digitalWrite(pinx, HIGH);
  pinMode(piny, INPUT);
  digitalWrite(piny, LOW);
 
  Serial.begin(9600);
}

void loop(){
  
  
if{pinx==HIGH}
(switch1= LOW);
else
(switch1= HIGH);

if {piny== LOW}
(switch2= HIGH);
else
(switch2= LOW);

state1= digitalRead(switch1);
state2= digitalRead(switch2);

if {state1== HIGH && state2== HIGH}
(outcome= LOW);
servo1.detach():
servo2.detach();
else
(outcome= HIGH);
{ if {pinx == HIGH}
servo2.write(180);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  }

& here is the Circuit diagram(with one servo):
https://picasaweb.google.com/112167713973931126525/Mar142011?authkey=Gv1sRgCPyaydmc6I_3Lg#5583810331328981426

Here is the complete code:

#include <Servo.h> 
 
Servo servo1; 
Servo servo2;  // create servo object to control a servo 
 int pinx;               // a maximum of eight servo objects can be created 
 int piny
 
//int pos = 0; 
void setup(){
  
  servo1.attach(9);  // attaches the servo on pin 9 to the servo object 
  servo2.attach(10);

  // declaration of pin modes
  pinMode(pinx, INPUT);
  digitalWrite(pinx, HIGH);
  pinMode(piny, INPUT);
  digitalWrite(piny, LOW);
 
  Serial.begin(9600);
}

void loop(){
  
  
if{pinx==HIGH}
(switch1= LOW);
else
(switch1= HIGH);

if {piny== LOW}
(switch2= HIGH);
else
(switch2= LOW);

state1= digitalRead(switch1);
state2= digitalRead(switch2);

if {state1== HIGH && state2== HIGH}
(outcome= LOW);
servo1.detach():
servo2.detach();
else
(outcome= HIGH);
{ if {pinx == HIGH}
(servo1.write(180);              // tell servo to go to position in variable 'pos' 
    delay(15);)    // waits 15ms for the servo to reach the position 
  else{servo2.write(180)};  
  } 
{ if {pinx && piny = LOW}
{servo1.write(180);
{servo2.write(180)}
}
else{servo1.detach();
servo2.detach();
}
}

Re the circuit, do you need the transistor. If so you realize that it inverts the signal.

Re the code, you seem to have swapped ( for { and vv. That will never compile let alone work.

Hint

if {state1== HIGH && state2== HIGH}
(outcome= LOW);

should be

if (state1== HIGH && state2== HIGH)
{
outcome= LOW;
};


Rob

Thanks Rob,
But I guess I dont need the ‘outcome’ at all

I have changed the code a bit

#include <Servo.h> 
 
Servo servo1; 
Servo servo2;  // create servo object to control a servo 
 int pinx;               // a maximum of eight servo objects can be created 
 int piny;
 int switch1;
 int switch2;
 int state1;
 int state2;
 
//int pos = 0; 
void setup(){
  
  servo1.attach(9);  // attaches the servo on pin 9 to the servo object 
  servo2.attach(10);

  // declaration of pin modes
  pinMode(pinx, INPUT);
  digitalWrite(pinx, HIGH); //pullup
  pinMode(piny, INPUT);
  digitalWrite(piny, LOW);// pulldown
 
  Serial.begin(9600);
}

void loop(){
  
  
if (pinx==HIGH)
{switch1= LOW;}
else
(switch1= HIGH);

if (piny== LOW)
{switch2= HIGH;}
else
(switch2= LOW);

state1= digitalRead(switch1);
state2= digitalRead(switch2);

if (state1== HIGH && state2== HIGH)
{servo1.detach();
servo2.detach();
}

else
{ if (pinx == HIGH)
{servo1.write(180);              // tell servo to go to position in variable 'pos' 
    delay(15);}    // waits 15ms for the servo to reach the position 
  else{servo2.write(180);}  
  } 
if (pinx && piny == LOW)
{servo1.write(180);
{servo2.write(180);}
}
else{servo1.detach();
servo2.detach();
}
}

Re the circuit, do you need the transistor. If so you realize that it inverts the signal.

How do I do that?

annapurnab: How do I do that?

Annapurnab,

you'll be best advised in not using any program fragments you don't understand. Before going on, you really should go back to the basics of programming, specially what variables are, and reread the documentation of all functions you use and understand the meaning of each parameter. The last code you posted looks as if a swarm of blind sparrows assembled it from line of code they found on random Arduino pages. It does a lot of things I'm absolutely certain you don't want it to do.

Going by your other posts, your understanding of computers, programming and electronics is just not enough to even properly extend such simple examples. You really should spend some more time on the basics, otherwise all answers you'll get will just be wasted and lead to more problems than they solve.

Good luck.

Korman

 pinMode(piny, INPUT);
  digitalWrite(piny, LOW);// pulldown

There are no built-in pull-downs, so it is best not rely on them.

 pinMode(pinx, INPUT);

You haven't given "pinx" a value, so the compiler took the liberty of setting it to zero for you. You've just set the serial Rx line to be an input.

if (pinx==HIGH)

The value of "pinx" has been explained to you, so you'll have to wait a long time for it to == 1.

What Korman said (though I'm not sure about the sparrows. Inebriated starlings, maybe?)

This is getting to be something of a habit: http://arduino.cc/forum/index.php/topic,55279.0.html

I am a newbie in this. I am eager to know about it. some help might be a driving force for me.

some help might be a driving force for me

Build some foundations - understand the concepts. Don't over-reach.