330Views0Replies

Author Options:

Make and,xor gate together using arduino Answered

Hi,I want to combine two logic gates in a single arduino code using arduino uno.These gates are and gate,xor gate.I added the sketch of the circuit below.I wrote the codes for the two logic gates, but I can't combine them.how can i make this circui?.Please HELP ME ! :)

Comments

The forums are retiring in 2021 and are now closed for new topics and comments.
0
Orngrimm
Orngrimm

1 year ago

XOR: z = x ^ y; // where Z is Output, X is first switch, Y is second switch
AND: z = x & y;

This would lead to something like
-----------
const int firstswitchPin = 2;
const int secondswitchPin = 3;
const int behaviourswitchPin = 4; // To choose XOR / AND

const int ledPin = 13;

boolean x = false;
boolean y = false;
boolean z = false;
boolean b = false;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(firstswitchPin, INPUT);
pinMode(secondswitchPin, INPUT);
pinMode(behaviourswitchPin, INPUT);
}

void loop() {
b = digitalRead(behaviourswitchPin);
x = digitalRead(firstswitchPin);
y = digitalRead(secondswitchPin);

if (b == true) {
z = x ^ y; // XOR
} else {
z = x & y; // AND
}
digitalWrite(ledPin, z);
}
-----------------------