I'm trying to make a system for my blinds where when I push a button it goes up and then a different button makes them come down. I'm trying to make a system where when I push "Up" once it won't let me do anything if it's pushed a second time, as I don't want my blinds to keep winding once already up. I'm trying to add 1 to an integer "i" when the blinds go up, and subtract 1 when I bring the blinds back down. I'm using an if statement to make sure the blinds are down if I'm trying to make them go back up and vice versa, but something isn't working right. When I push the up button again on my remote it seems to override the if statement and just go "Up" again. I've attempted to fix it in various ways but I'm not sure what I'm doing wrong. Any help would be much appreciated.
Here's my code.
#include <IRremote.h>
#include <IRremoteInt.h>
long x;
int receiver = 12;
IRrecv irrecv(receiver);
decode_results results;
void setup()
{
Serial.begin(9600);
x = 0;
Serial.print("X=");
Serial.println(x);
{
irrecv.enableIRIn(); //Start receiver
}
}
void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
switch(results.value)
{
case 0xFF906F: // VOL+ button pressed
{
if(x=0)
{
Serial.println("Up");
delay(2000);
(x++);
}
}
break;
case 0xFFE01F: // VOL- button pressed
{
if(x=1)
{
Serial.println("Down");
delay(2000);
(x--);
}
}
break;
}
irrecv.resume(); // receive the next value
}
}/* --end main loop -- */