In this code can you have the two if else statements? and is there an easier way to approach this?
const int leftbutton = 4;
const int rightbutton = 2;
const int yellow = 13;
const int red = 12;
const int comp = 1;
const int comp2 = 2;
int x;
int buttonstate = 0;
void setup()
{
pinMode(leftbutton, INPUT);
pinMode(yellow, OUTPUT);
pinMode(red, OUTPUT);
pinMode(rightbutton, INPUT);
}
// to read the button state do buttonState = digitalRead(buttonPin);
//basically the state = digitalRead(pin of button output);
//If button one(comp) is == to x, then light up the yellow light.
//else turn on the red led
//digitalWrite(pin, LOW/HIGH)
void loop()
{ // 1 is the right one
x = random(1,2);
//If the leftbutton is pressed and the number is rand num is 1, tu
if(((buttonstate = digitalRead(leftbutton) == HIGH) && (x == comp)))
{
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
}
else
{
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
}
if(((buttonstate = digitalRead(rightbutton) == HIGH) && (x == comp)))
{
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
}
else
{
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
}
}