Hello,
I've searched around for exclusive logic gates and they don't seem to exist in Arduino language, but I'm sure there's a way around this. It's Arduino!
I have 2 pushbuttons (pins 5 and 8) and 2 LEDs (pins 12 and 13)
I want
button 5 AND 8 to blink both LEDs
button 5 to turn on LED 12
button 8 to turn on LED 13
I wonder if it would be possible to have some sort of exlusion, like XAND that would say :
turn on LED 12 and only LED 12 if button 5 and only button 5 is HIGH
turn on LED 13 and only LED 13 if button 8 and only button 8 is HIGH
blink both LEDs if buttons 5 AND 8 and only if buttons 5 AND 8 are HIGH
here's the code I made up,
button 5 turns on LED 12
button 8 turns on LED 13
both buttons blink LED 13 and turn on LED 12 with no blinking
const int buttonPin2 = 2;
const int buttonPin5 = 5;
const int buttonPin8 = 8;
const int ledPin12 = 12;
const int ledPin13 = 13;
int buttonState2 = 0;
int buttonState5 = 0;
int buttonState8 = 0;
void setup()
{
pinMode(ledPin12, OUTPUT);
pinMode(ledPin13, OUTPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin5, INPUT);
pinMode(buttonPin8, INPUT);
}
void loop()
{
buttonState2 = digitalRead(buttonPin2);
buttonState5 = digitalRead(buttonPin5);
buttonState8 = digitalRead(buttonPin8);
if (buttonState5 == HIGH && buttonState8 == HIGH)
{
digitalWrite(ledPin12, HIGH);
digitalWrite(ledPin12, HIGH);
delay(100);
digitalWrite(ledPin13, LOW);
digitalWrite(ledPin13, LOW);
delay(100);
}
if (buttonState5 == HIGH)
{
digitalWrite(ledPin12, HIGH);
}
if (buttonState8 == HIGH )
{
digitalWrite(ledPin13, HIGH);
}
else
{
digitalWrite(ledPin12, LOW);
digitalWrite(ledPin13, LOW);
}
}
I also tried it with by implementing a third button for blinking
3 pushbuttons (pins 2,5 and 7) and 2 LEDs (pins 12 and 13)
I want
button 2 to blink both LEDs
button 5 to turn on LED 12
button 8 to turn on LED 13
here's the code I made up,
button 5 turns on LED 12
button 8 turns on LED 13
button 2 turns on LED 12 no blinking
const int buttonPin2 = 2;
const int buttonPin5 = 5;
const int buttonPin8 = 8;
const int ledPin12 = 12;
const int ledPin13 = 13;
int buttonState2 = 0;
int buttonState5 = 0;
int buttonState8 = 0;
void setup()
{
pinMode(ledPin12, OUTPUT);
pinMode(ledPin13, OUTPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin5, INPUT);
pinMode(buttonPin8, INPUT);
}
void loop()
{
buttonState2 = digitalRead(buttonPin2);
buttonState5 = digitalRead(buttonPin5);
buttonState8 = digitalRead(buttonPin8);
if (buttonState2 == HIGH)
{
digitalWrite(ledPin12, HIGH);
digitalWrite(ledPin12, HIGH);
delay(100);
digitalWrite(ledPin13, LOW);
digitalWrite(ledPin13, LOW);
delay(100);
}
if (buttonState5 == HIGH)
{
digitalWrite(ledPin12, HIGH);
}
if (buttonState8 == HIGH )
{
digitalWrite(ledPin13, HIGH);
}
else
{
digitalWrite(ledPin12, LOW);
digitalWrite(ledPin13, LOW);
}
}
Thanks!