So, i've included a section of a larger code i'm working on, what I am trying to do it get all of my legs to flash using prevails etc which works fine, then on the press of the same IR button they switch off. What happens with this code is that they stop flashing at whatever state they are in at the time of the button press, so they stay on if they are on and off if they are off.
If I reduce the line:
digitalWrite(ledred && ledblue && ledgreen && led && leda && ledb, LOW);
to:
digitalWrite(ledred, LOW);
then they all flash and when the button is pressed with the lads on, the red turns off and the rest stay on.
if I then separate into a few lines of code like this:
digitalWrite(ledred, LOW);
digitalWrite(ledblue, LOW);
digitalWrite(ledgreen, LOW);
digitalWrite(led, LOW);
Only the red will flash the others will stay off all the time.
I am assuming that this is some sort of timing issue but I barely understand the prelims thing and timing, if someone could suggest where I am going wrong i'd appreciate it!
#include <IRremote.h>
int led = 13;
int leda = 12;
int ledb = 7; //was 11
int ledblue = 10;
int ledgreen = 9;
int ledred = 8;
int irPin = 11; //ir sensor pin
int flickstate = LOW;
long prevMillis = 0;
long interval = 300; //time between flashes
bool RedLed=false;
bool blueLed=false;
bool greenLed=false;
bool whiteLed=false;
bool flick=false;
IRrecv irrecv(irPin);
decode_results results;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
irrecv.enableIRIn(); //starts IR reciever
pinMode(led, OUTPUT);
pinMode(leda, OUTPUT);
pinMode(ledb, OUTPUT);
pinMode(ledblue, OUTPUT);
pinMode(ledgreen, OUTPUT);
pinMode(ledred, OUTPUT);
}
void loop(){
if (irrecv.decode(&results)){
long int decCode = results.value;
switch (results.value){
case 524543: // power button
flick=!flick;
break;
}
irrecv.resume();
}
if(flick)
{
flicker();
}
else
digitalWrite(ledred && ledblue && ledgreen && led && leda && ledb, LOW);
}
void flicker()
{
unsigned long currentMillis = millis();
if(currentMillis - prevMillis > interval)
{
prevMillis = currentMillis;
if (flickstate == 0)
flickstate = 1;
else
flickstate = 0;
digitalWrite(ledblue, flickstate);
digitalWrite(ledred, flickstate);
digitalWrite(ledgreen, flickstate);
digitalWrite(led, flickstate);
digitalWrite(leda, flickstate);
digitalWrite(ledb, flickstate);
}
}