If statement being ignored?

At least, that's what I think is happening. I have an Arduino Fio recognizing a button press and sending an XBee packet to an Arduino Uno with the SparkFun XBee shield. The goal is to activate two NeoMatrix panels remotely with a button press or when the signal strength is above a threshold (yes, I realize RSSI is a terrible indicator for distance, but this is a parlor trick type of project).

The two if statements work fine independently, but when the RSSI if statement is run I can no longer run the data if statement. When I start the sketch, the data if statement works. It's only after the RSSI if statement runs that the data if statement no longer works.

I feel like I must be missing something extremely simple.

void loop(){
xbee.readPacket();

      // check XBee on Fio
      if (xbee.getResponse().isAvailable()) {
        
       // got something
        xbee.getResponse().getRx16Response(rx16);
        data = rx16.getData(0);
        rssi = rx16.getRssi();

        //Serial.print("RSSI: ");
        //Serial.print(rssi);
        //Serial.println();
        //Serial.print("Data: ");
        //Serial.print(data);
        //Serial.println();        

        //get angry
        if (rssi >=65){

          // lightning effect
          delay(50);
          angryLightning(0.08);
          delay(50);
          angryLightning(0.175);
          delay(50);


        }
        // pretty lights
        else if (data == 49){
          
          rainbow(10);

        }
      }
}

void angryLightning(float SpeedFactor){

  // Make the lights breathe
  for (int i = 0; i < 100; i++) {
    // Intensity will go from 10 - MaximumBrightness in a "breathing" manner
    float intensity = MaximumBrightness /2.0 * (1.0 + sin(SpeedFactor * i));
    lStrip.setBrightness(intensity);
    tStrip.setBrightness(intensity);
    // Now set every LED to that color
    for (int ledNumber=0; ledNumber<TOTAL_LEDS; ledNumber++) {
      lStrip.setPixelColor(ledNumber, 250, 0, 0);
      tStrip.setPixelColor(ledNumber, 250, 0, 0);
    }

    lStrip.show();
    tStrip.show();
    //Wait a bit before continuing to breathe
    delay(StepDelay);
  } 
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 165 - WheelPos;
  if(WheelPos < 85) {
    return lStrip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
    return tStrip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } 
  else if(WheelPos < 170) {
    WheelPos -= 85;
    return lStrip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
    return tStrip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  } 
  else {
    WheelPos -= 170;
    return lStrip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
    return tStrip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<lStrip.numPixels(); i++) {
      lStrip.setPixelColor(i, Wheel((i+j) & 255));
      tStrip.setPixelColor(i, Wheel((i+j) & 255));
    }
    lStrip.show();
    tStrip.show();
    delay(wait);
  }
}

Delta_G:
Since the data part is in an else if instead of it's own if, it won't ever get to that code if rssi is above the threshold in its if statement.

Just gave that a try and same thing. Data if statement runs if I trigger it first, but once the RSSI if statement runs, I can no longer trigger the data if statement. I can trigger the RSSI statement on and off though (move the Arduino Fio behind things and bring it back closer).

Still stumped.

Your Wheel() function looks like nonsense.

You can't have a return statement followed by another return statement.

What datatype is the identifier rx16 supposed to be ?

Delta_G:
It is a shame I can't see the new try. I'd be happy to try to help you find the problem.

Sorry, here's the code I tried:

xbee.readPacket();

  // check XBee on Gauntlet
  if (xbee.getResponse().isAvailable()) {
    // got something

    // create a response
    xbee.getResponse().getRx16Response(rx16);
    data = rx16.getData(0);
    rssi = rx16.getRssi();
    //Serial.print("RSSI: ");
    //Serial.print(rssi);
    //Serial.println();
    //Serial.print("Data: ");
    //Serial.print(data);
    //Serial.println();        


    // button is pressed
    // pretty lights

    if (data == 49){
      fadeIn(10);
      rainbow(10);
      cd77colorallfill();
      delay(50);

    }

    // if Mjolnir is too far from the gauntlet 
    //get angry
    if (rssi >=80){

      //Mjolnir Gets Angry
      // lightning effect
      delay(50);
      angryLightning(0.08);
      delay(50);
      angryLightning(0.175);
      delay(50);

    }

  }

michinyon:
Your Wheel() function looks like nonsense.

You can't have a return statement followed by another return statement.

Yeah, I can't quite wrap my head around it, but it's taken directly from the NeoPixel library example. I'll take a look at it to make sure I didn't leave off something important.

michinyon:
What datatype is the identifier rx16 supposed to be ?

rx16 is an 16 bit XBee response from the XBee Arduino Library

Also, if you're a visual person like me and want to see the actual effect here you go

Delta_G:
Can you please post the complete code. There are some variable definitions that are missing from the two posts where you have code. I'm looking for stepDelay and wait. But it would be nice to be able to see the complete code.

Roger. I was trying to keep it simple and post the relevant portion, but it is sort of all entwined. I have portions commented out so that I'm only testing what I'm having issues with.

#include <Narcoleptic.h>
#include <Adafruit_NeoPixel.h>
#include <SoftwareSerial.h>
#include <XBee.h>

/*****************************/
/***** NeoPixel Setup ********/
/*****************************/

#define lPIN 6
#define tPIN 9

//Lightning Code
//Written by: Jason Yandell  
int TOTAL_LEDS = 64;
float MaximumBrightness = 255;
float StepDelay = 5; // ms for a step delay on the lights

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel lStrip = Adafruit_NeoPixel(TOTAL_LEDS, lPIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel tStrip = Adafruit_NeoPixel(TOTAL_LEDS, tPIN, NEO_GRB + NEO_KHZ800);

/*************************************/
/***** Vibration Sensor Setup ********/
/*************************************/

const int sensorPin =  7;      // the number of the sensor pin

/********************************/
/***** XBee Sensor Setup ********/
/********************************/


SoftwareSerial xbeeSerial(2, 3); // Arduino RX, TX (XBee Dout, Din)

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
//Create reusable response objects for responses we expect to handle
Rx16Response rx16 = Rx16Response();

//data is activation from muscle sensor
uint8_t data = 0;
//rssi is signal strength for proximity of gauntlet to mjolnir
uint8_t rssi = 0;


/***************************/
/***** Switch Setup ********/
/***************************/
const int switchWait = 2;
const int switchOn = 3;

void setup(){

  // initalize NeoPixel
  lStrip.begin();
  tStrip.begin();
  lStrip.show(); // Initialize all pixels to 'off'
  tStrip.show(); // Initialize all pixels to 'off'

  // initialize the sensor pin as an input & enable the pullups
  pinMode(sensorPin, INPUT_PULLUP);  

  // initialize Serial for XBee communication
  Serial.begin(57600);
  xbee.setSerial(Serial);

  //initalize Switch
  pinMode(switchWait, INPUT_PULLUP);
  pinMode(switchOn, INPUT_PULLUP);
  digitalWrite(switchOn, HIGH);
  digitalWrite(switchWait, HIGH);
}

void loop() {

  //Narcoleptic.delay(500); // During this time power consumption is minimised


  //while (digitalRead(switchOn) == LOW || digitalRead(switchWait) == LOW){

  //if (digitalRead(switchWait) == LOW && digitalRead(switchOn) == HIGH){
  xbee.readPacket();

  // check XBee on Gauntlet
  if (xbee.getResponse().isAvailable()) {
    // got something

    // create a response
    xbee.getResponse().getRx16Response(rx16);
    data = rx16.getData(0);
    rssi = rx16.getRssi();
    //Serial.print("RSSI: ");
    //Serial.print(rssi);
    //Serial.println();
    //Serial.print("Data: ");
    //Serial.print(data);
    //Serial.println();        


    // button is pressed
    // pretty lights

    if (data == 49){
      fadeIn(10);
      rainbow(10);
      cd77colorallfill();
      delay(50);

    }

    // if Mjolnir is too far from the gauntlet 
    //get angry
    if (rssi >=80){

      //Mjolnir Gets Angry
      // lightning effect
      delay(50);
      angryLightning(0.08);
      delay(50);
      angryLightning(0.175);
      delay(50);

    }

  }
  // check the Vibration Sensor  
  if (digitalRead(sensorPin) == LOW){

    cd77colorallfillOn();
    delay(25);
    cd77colorallfill();


  }
}

//if (digitalRead(switchOn) == LOW && digitalRead(switchWait == HIGH)){
//cd77colorallfillOn(200);
//}

//}

//cd77colorallfill(200);


//}

void angryLightning(float SpeedFactor){

  // Make the lights breathe
  for (int i = 0; i < 100; i++) {
    // Intensity will go from 10 - MaximumBrightness in a "breathing" manner
    float intensity = MaximumBrightness /2.0 * (1.0 + sin(SpeedFactor * i));
    lStrip.setBrightness(intensity);
    tStrip.setBrightness(intensity);
    // Now set every LED to that color
    for (int ledNumber=0; ledNumber<TOTAL_LEDS; ledNumber++) {
      lStrip.setPixelColor(ledNumber, 250, 0, 0);
      tStrip.setPixelColor(ledNumber, 250, 0, 0);
    }

    lStrip.show();
    tStrip.show();
    //Wait a bit before continuing to breathe
    delay(StepDelay);
  } 
}

// Fills the NeoMatrix 8X8 panel with all of the NeoPixes at one time 
void cd77colorallfillOn() {  
  for(uint16_t i=0; i<lStrip.numPixels(); i++) {
    lStrip.setPixelColor(i, lStrip.Color(88, 195, 185));   
    tStrip.setPixelColor(i, tStrip.Color(88, 195, 185));   
  }       
  lStrip.show();
  tStrip.show();
  //delay(wait);
}

void cd77colorallfill() {  
  for(uint16_t i=0; i<lStrip.numPixels(); i++) {
    lStrip.setPixelColor(i, lStrip.Color(0, 0, 0));   
    tStrip.setPixelColor(i, tStrip.Color(0, 0, 0));   
  }       
  lStrip.show();
  tStrip.show();
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 165 - WheelPos;
  if(WheelPos < 85) {
    return lStrip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
    return tStrip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } 
  else if(WheelPos < 170) {
    WheelPos -= 85;
    return lStrip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
    return tStrip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  } 
  else {
    WheelPos -= 170;
    return lStrip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
    return tStrip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<lStrip.numPixels(); i++) {
      lStrip.setPixelColor(i, Wheel((i+j) & 255));
      tStrip.setPixelColor(i, Wheel((i+j) & 255));
    }
    lStrip.show();
    tStrip.show();
    delay(wait);
  }
}

void fadeIn(int waitT)
{
  int R = 0;
  int G = 0;
  int B = 0;
  int finCount=30;
  int Rset = 255;
  int Gset = 255;
  int Bset = 255;

  //Fade in
  while(1){ //using an inf loop to be more custom.

    //break the inf loop if the color is higher then what its set at.
    if (R>Rset+1 && G>Gset+1 && B>Bset+1)  { 
      //ReSet the RGB to set values. 
      R=Rset;
      G=Gset;
      B=Bset;
      break; 
    } 
    //update the strip
    for(int i=0; i<lStrip.numPixels(); i++) {
      lStrip.setPixelColor(i, lStrip.Color(R, G, B));
      tStrip.setPixelColor(i, tStrip.Color(R, G, B));
      lStrip.show();
      tStrip.show();
    }
    //increase by the set amount
    R=R+finCount;
    G=G+finCount;
    B=B+finCount;
    delay(waitT);
  }
}

I decided to try something very simple to see if it's the if statements or the pretty color functions:

#include <Adafruit_NeoPixel.h>
#include <SoftwareSerial.h>
#include <XBee.h>

/*****************************/
/***** NeoPixel Setup ********/
/*****************************/

#define lPIN 6
#define tPIN 9

//Lightning Code
//Written by: Jason Yandell  
int TOTAL_LEDS = 64;
float MaximumBrightness = 255;
float StepDelay = 5; // ms for a step delay on the lights

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel lStrip = Adafruit_NeoPixel(TOTAL_LEDS, lPIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel tStrip = Adafruit_NeoPixel(TOTAL_LEDS, tPIN, NEO_GRB + NEO_KHZ800);

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
//Create reusable response objects for responses we expect to handle
Rx16Response rx16 = Rx16Response();

//data is activation from muscle sensor
uint8_t data = 0;
//rssi is signal strength for proximity of gauntlet to mjolnir
uint8_t rssi = 0;


/***************************/
/***** Switch Setup ********/
/***************************/
const int switchWait = 2;
const int switchOn = 3;



void setup() {
  // put your setup code here, to run once:
 // initalize NeoPixel
  lStrip.begin();
  tStrip.begin();
  lStrip.show(); // Initialize all pixels to 'off'
  tStrip.show(); // Initialize all pixels to 'off'

  // initialize Serial for XBee communication
  Serial.begin(57600);
  xbee.setSerial(Serial);
}

void loop() {
  // put your main code here, to run repeatedly: 

  xbee.readPacket();

  // check XBee on Gauntlet
  if (xbee.getResponse().isAvailable()) {
    // got something

    // create a response
    xbee.getResponse().getRx16Response(rx16);
    data = rx16.getData(0);
    rssi = rx16.getRssi();
    //Serial.print("RSSI: ");
    //Serial.print(rssi);
    //Serial.println();
    //Serial.print("Data: ");
    //Serial.print(data);
    //Serial.println();        


    // button is pressed
    // pretty lights

    if (data == 49){
      cd77colorallfillOnBlue();
      delay(200);
      cd77colorallfill();

    }

    // if Mjolnir is too far from the gauntlet 
    //get angry
    if (rssi >=80){

      //Mjolnir Gets Angry
      // lightning effect
      cd77colorallfillOnRed();
      delay(200);
      cd77colorallfill();

    }

  }

}



// Fills the NeoMatrix 8X8 panel with all of the NeoPixes at one time 
void cd77colorallfillOnBlue() {  
  for(uint16_t i=0; i<lStrip.numPixels(); i++) {
    lStrip.setPixelColor(i, lStrip.Color(88, 195, 185));   
    tStrip.setPixelColor(i, tStrip.Color(88, 195, 185));   
  }       
  lStrip.show();
  tStrip.show();
}

void cd77colorallfillOnRed() {  
  for(uint16_t i=0; i<lStrip.numPixels(); i++) {
    lStrip.setPixelColor(i, lStrip.Color(255 , 0, 0));   
    tStrip.setPixelColor(i, tStrip.Color(255 , 0, 0));   
  }       
  lStrip.show();
  tStrip.show();
}

void cd77colorallfill() {  
  for(uint16_t i=0; i<lStrip.numPixels(); i++) {
    lStrip.setPixelColor(i, lStrip.Color(0, 0, 0));   
    tStrip.setPixelColor(i, tStrip.Color(0, 0, 0));   
  }       
  lStrip.show();
  tStrip.show();
}

THIS works fine, so I think I've narrowed it down to the two pretty light functions as to why this isn't working as anticipated. Stay tuned.

Delta_G:
I'm pretty sure this one needs some work.

You can't have two return statements in the same branch. Syntactically it works, but the second one will never happen. The function exits at the first return statement it sees.

Now that I'm reading it carefully, that does seem odd. Sure does look pretty when it runs though. I've taken it out in favor of the simple FadeIn/FadeOut for now.

Delta_G:
In fadeIn, try giving these variables some more reasonable names. One letter names are usually bad. I noticed that G and B both turned blue in my editor which means they are defined somewhere.

Hmmm....not sure where it's catching it, but I've updated to have more meaningful names. This looks pretty decent for the time being and works. I'd much rather have the color version working so I'll keep digging in.

#include <Narcoleptic.h>
#include <Adafruit_NeoPixel.h>
#include <SoftwareSerial.h>
#include <XBee.h>

/*****************************/
/***** NeoPixel Setup ********/
/*****************************/

#define lPIN 6
#define tPIN 9

//Lightning Code
//Written by: Jason Yandell  
int TOTAL_LEDS = 64;
float MaximumBrightness = 255;
float StepDelay = 5; // ms for a step delay on the lights

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel lStrip = Adafruit_NeoPixel(TOTAL_LEDS, lPIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel tStrip = Adafruit_NeoPixel(TOTAL_LEDS, tPIN, NEO_GRB + NEO_KHZ800);

/*************************************/
/***** Vibration Sensor Setup ********/
/*************************************/

const int sensorPin =  7;      // the number of the sensor pin

/********************************/
/***** XBee Sensor Setup ********/
/********************************/


SoftwareSerial xbeeSerial(2, 3); // Arduino RX, TX (XBee Dout, Din)

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
//Create reusable response objects for responses we expect to handle
Rx16Response rx16 = Rx16Response();

//data is activation from muscle sensor
uint8_t data = 0;
//rssi is signal strength for proximity of gauntlet to mjolnir
uint8_t rssi = 0;


/***************************/
/***** Switch Setup ********/
/***************************/
const int switchWait = 2;
const int switchOn = 3;

void setup(){

  // initalize NeoPixel
  lStrip.begin();
  tStrip.begin();
  lStrip.show(); // Initialize all pixels to 'off'
  tStrip.show(); // Initialize all pixels to 'off'

  // initialize the sensor pin as an input & enable the pullups
  pinMode(sensorPin, INPUT_PULLUP);  

  // initialize Serial for XBee communication
  Serial.begin(57600);
  xbee.setSerial(Serial);

  //initalize Switch
  pinMode(switchWait, INPUT_PULLUP);
  pinMode(switchOn, INPUT_PULLUP);
  digitalWrite(switchOn, HIGH);
  digitalWrite(switchWait, HIGH);
}

void loop() {

  //Narcoleptic.delay(500); // During this time power consumption is minimised


  //while (digitalRead(switchOn) == LOW || digitalRead(switchWait) == LOW){

  //if (digitalRead(switchWait) == LOW && digitalRead(switchOn) == HIGH){
  xbee.readPacket();

  // check XBee on Gauntlet
  if (xbee.getResponse().isAvailable()) {
    // got something

    // create a response
    xbee.getResponse().getRx16Response(rx16);
    data = rx16.getData(0);
    rssi = rx16.getRssi();
    //Serial.print("RSSI: ");
    //Serial.print(rssi);
    //Serial.println();
    //Serial.print("Data: ");
    //Serial.print(data);
    //Serial.println();        


    // button is pressed
    // pretty lights

    if (data == 49){

      fade();


    }

    // if Mjolnir is too far from the gauntlet 
    //get angry
    if (rssi >=80){

      //Mjolnir Gets Angry
      // lightning effect
      angryLightning();

    }

  }
  // check the Vibration Sensor  
  if (digitalRead(sensorPin) == LOW){

    cd77colorallfillOn();
    delay(25);
    cd77colorallfill();


  }
}

//if (digitalRead(switchOn) == LOW && digitalRead(switchWait == HIGH)){
//cd77colorallfillOn(200);
//}

//}

//cd77colorallfill(200);


//}

// Fills the NeoMatrix 8X8 panel with all of the NeoPixes at one time 
void cd77colorallfillOn() {  
  for(uint16_t i=0; i<lStrip.numPixels(); i++) {
    lStrip.setPixelColor(i, lStrip.Color(88, 195, 185));   
    tStrip.setPixelColor(i, tStrip.Color(88, 195, 185));   
  }       
  lStrip.show();
  tStrip.show();

}

// Fills the NeoMatrix 8X8 panel with all of the NeoPixes at one time 
void cd77colorallfillOnRed() {  
  for(uint16_t i=0; i<lStrip.numPixels(); i++) {
    lStrip.setPixelColor(i, lStrip.Color(255, 0, 0));   
    tStrip.setPixelColor(i, tStrip.Color(255, 0, 0));   
  }       
  lStrip.show();
  tStrip.show();

}

void cd77colorallfill() {  
  for(uint16_t i=0; i<lStrip.numPixels(); i++) {
    lStrip.setPixelColor(i, lStrip.Color(0, 0, 0));   
    tStrip.setPixelColor(i, tStrip.Color(0, 0, 0));   
  }       
  lStrip.show();
  tStrip.show();
}



void fade()
{
  int Red= 0;
  int Green = 0;
  int Blue = 0;
  int finCount=5;
  int foutCount=5;
  int redSet = 125;
  int greenSet = 125;
  int blueSet = 125;
  int waitT = 5;
  //Fade in
  while(1){ //using an inf loop to be more custom.
  //Protect the strand from higher then 255 values
  if(Red>255 || Green>255 || Blue>255) { break; } //DO NOT DELETE OR ALTER THIS LINE.
    //break the inf loop if the color is higher then what its set at.
    if (Red>redSet+1 && Green>greenSet+1 && Blue>blueSet+1)  { 
      //ReSet the RGB to set values. 
      Red=redSet;
      Green=greenSet;
      Blue=blueSet;
      break; 
    } 
    //update the strip
    for(int i=0; i<tStrip.numPixels(); i++) {
      tStrip.setPixelColor(i, tStrip.Color(Red, Green, Blue));
      lStrip.setPixelColor(i, tStrip.Color(Red, Green, Blue));
      tStrip.show();
      lStrip.show();
      delay(0);
    }
    //increase by the set amount
    Red=Red+finCount;
    Green=Green+finCount;
    Blue=Blue+finCount;
    delay(waitT);
  }
  //Fade Out
  while(1){ //using an inf loop to be more custom.
  //Protect the strand from higher then 255 values
  if(Red>255 || Green>255 || Blue>255) { break; } //DO NOT DELETE OR ALTER THIS LINE.
  //break the inf loop if the color is off
    if (Red<0 && Green<0 && Blue<0)  { 
      //ReSet the RGB to 0 values. 
      Red=0;
      Green=0;
      Blue=0;
      break; 
    } 
    //update the strip
    for(int j=0; j<tStrip.numPixels(); j++) {
      tStrip.setPixelColor(j, tStrip.Color(Red, Green, Blue));
      lStrip.setPixelColor(j, tStrip.Color(Red, Green, Blue));
      tStrip.show();
      lStrip.show();
      delay(0);
    }
    //Decrease by the set amount
    Red=Red-foutCount;
    Green=Green-foutCount;
    Blue=Blue-foutCount;
    delay(waitT);
  }
}

void angryLightning()
{cd77colorallfillOnRed();
      delay(100);
      cd77colorallfill();
      delay(100);
      cd77colorallfillOnRed();
      delay(50);
      cd77colorallfill();
      delay(100);
      cd77colorallfillOnRed();
      delay(500);
      cd77colorallfill();
      delay(100);
      cd77colorallfillOnRed();
      delay(200);
      cd77colorallfill();
}

//if (digitalRead(switchOn) == LOW && digitalRead**(switchWait == HIGH)**){

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
}

This is the code you took yours directly from, and it doesn't have a problem with the return statements that yours has.

michinyon:

// Input a value 0 to 255 to get a color value.

// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
}




This is the code you took yours directly from, and it doesn't have a problem with the return statements that yours has.

When I read this post, I realized I haven't actually tested this portion of code with both matrices. Since both panels are displaying the same colors in the same order, I can return just one strip of color and it'll update both matrices appropriately in the rainbow function.

However, even with this code change, I'm still running in to the same problem.

Alright, I altered the angryLightning function to just simply flash on and off and kept the rainbow function the same. This works. So I think I've narrowed it down to the angryLightning function causing issues.

void angryLightning(float SpeedFactor){

  /* / Make the lights breathe
  for (int i = 0; i < 100; i++) {
    // Intensity will go from 10 - MaximumBrightness in a "breathing" manner
    float intensity = MaximumBrightness /2.0 * (1.0 + sin(SpeedFactor * i));
    lStrip.setBrightness(intensity);
    tStrip.setBrightness(intensity);
    // Now set every LED to that color
    for (int ledNumber=0; ledNumber<TOTAL_LEDS; ledNumber++) {
      lStrip.setPixelColor(ledNumber, 250, 0, 0);
      tStrip.setPixelColor(ledNumber, 250, 0, 0);
    }

    lStrip.show();
    tStrip.show();
    //Wait a bit before continuing to breathe
    //delay(StepDelay);
  } */
  cd77colorallfillOn(20);
  cd77colorallfill(20);
}