IFTTT, Photon, and NeoPixel - Call a function updating a variable

Hi all,

I’ve done some searching around the forum but I haven’t found someone with the same issue. Please feel free to link me if I’m blind. Also, I’m relatively new to this and this is my first project that I haven’t 100% copied the code for.

I’m trying to create a program that updates what NeoPixel is turned on based on location triggers from IFTTT. A slight twist on the Weasley location clock from Harry Potter, but for just 2 people. Once I trigger IFTTT by entering or exiting an area I have it call a function and send back a number. I then use this number to turn on the corresponding LED. Everything seems to be working except that the previously triggered LED is staying on. In my IFTTT function I’ve put a line to turn off all of the LEDs in the strip, but it seems like it is retaining the old number. I was under the impression that the new event would overwrite my variable. Is that not the case? Any suggestions? Thank you in advance for you help!

// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>


// What is this? Taken from NeoPixel Example
SYSTEM_MODE(AUTOMATIC);


#define Andrew_PIXEL_COUNT 15
#define Andrew_PIXEL_PIN D6
#define Andrew_PIXEL_TYPE WS2812B
#define Darbie_PIXEL_COUNT 15
#define Darbie_PIXEL_PIN D5
#define Darbie_PIXEL_TYPE WS2812B


int AndrewLED = 0; //Variable to store Andrew's LED
int DarbieLED = 0; //Variable to store Darbie's LED


Adafruit_NeoPixel Andrew_strip = Adafruit_NeoPixel(Andrew_PIXEL_COUNT, Andrew_PIXEL_PIN, Andrew_PIXEL_TYPE);
Adafruit_NeoPixel Darbie_strip = Adafruit_NeoPixel(Darbie_PIXEL_COUNT, Darbie_PIXEL_PIN, Darbie_PIXEL_TYPE);



void setup()
{
  Andrew_strip.begin();
  Andrew_strip.show();
  Darbie_strip.begin();
  Darbie_strip.show();


  Particle.function("upd_a_LED", upd_A_LED); //Andrew's Particle Function
  Particle.function("upd_d_LED", upd_D_LED); //Darbie's Particle Function



  //Take control over the LED on the board
  RGB.control(true);
  //Turn off the LED - we dont want it flashing behind the photo frame at night
  RGB.color(255, 51, 255);
}

void loop() {

}

int upd_A_LED(String command)
{
  //Convert string to integer, the code after this requires the 'command' object to be in a number format. IFTTT however passes the object as a 'string' even if it is a 'number'.
  uint8_t AndrewLED = command.toInt();
  Andrew_strip.Color(0, 0, 0); //Clear Strip
  Andrew_strip.show();
  Andrew_strip.setPixelColor(AndrewLED, Andrew_strip.Color(0, 0, 255));
  Andrew_strip.show();

}


int upd_D_LED(String command)
{
  //Convert string to integer, the code after this requires the 'command' object to be in a number format. IFTTT however passes the object as a 'string' even if it is a 'number'.
  uint8_t DarbieLED = command.toInt();
  Darbie_strip.Color(0, 0, 0); //Clear Strip
  Darbie_strip.show();
  Darbie_strip.setPixelColor(DarbieLED, Darbie_strip.Color(255, 0, 0));
  Darbie_strip.show();

}

Exampled of a recipe.

You're making a new local variable inside the function, even though you've already got a global one.
Furthermore, the first strip.show shouldn't be necessary as all you're doing, is setting the values, and then update them all at once.

Thanks for the reply! Doh. I thought that was updating it to a specific type of integer, not making a whole new variable. That makes sense, thank you. That said… I thought I updated it so that I’m referencing the global variable instead of creating new local one, but I’m still having the same issue. I think I’m fundamentally misunderstanding something. Again, thank you for taking the time.

    // This #include statement was automatically added by the Particle IDE.
    #include <neopixel.h>


    // What is this? Taken from NeoPixel Example
    SYSTEM_MODE(AUTOMATIC);


    #define Andrew_PIXEL_COUNT 15
    #define Andrew_PIXEL_PIN D6
    #define Andrew_PIXEL_TYPE WS2812B
    #define Darbie_PIXEL_COUNT 15
    #define Darbie_PIXEL_PIN D5
    #define Darbie_PIXEL_TYPE WS2812B


    uint8_t AndrewLED = 0; //Variable to store Andrew's LED
    uint8_t DarbieLED = 0; //Variable to store Darbie's LED


    Adafruit_NeoPixel Andrew_strip = Adafruit_NeoPixel(Andrew_PIXEL_COUNT, Andrew_PIXEL_PIN, Andrew_PIXEL_TYPE);
    Adafruit_NeoPixel Darbie_strip = Adafruit_NeoPixel(Darbie_PIXEL_COUNT, Darbie_PIXEL_PIN, Darbie_PIXEL_TYPE);



    void setup()
    {
    Andrew_strip.begin();
    Andrew_strip.show();
    Darbie_strip.begin();
    Darbie_strip.show();

      
    Particle.function("upd_a_LED", upd_A_LED); //Andrew's Particle Function
    Particle.function("upd_d_LED", upd_D_LED); //Darbie's Particle Function



    //Take control over the LED on the board
    RGB.control(true);
    //Turn off the LED - we dont want it flashing behind the photo frame at night
    RGB.color(255, 51, 255);
    }
     
    void loop() {
        
    }

    int upd_A_LED(String command)
    {
    //Convert string to integer, the code after this requires the 'command' object to be in a number format. IFTTT however passes the object as a 'string' even if it is a 'number'.
    AndrewLED = command.toInt();
    Andrew_strip.Color(0,0,0); //Clear Strip
    Andrew_strip.setPixelColor(AndrewLED, Andrew_strip.Color(0, 0, 255));
    Andrew_strip.show();

    }


    int upd_D_LED(String command)
    {
    //Convert string to integer, the code after this requires the 'command' object to be in a number format. IFTTT however passes the object as a 'string' even if it is a 'number'.
    DarbieLED = command.toInt();
    Darbie_strip.Color(0,0,0); //Clear Strip
    Darbie_strip.setPixelColor(DarbieLED, Darbie_strip.Color(255, 0, 0));
    Darbie_strip.show();
       
    }

Does the function do what it is supposed to do when called via https://console.particle.io ?

You need to first find what part of the system is not working before guessing why.

You may also use RGB.color() inside your functions to see whether the function doesn't work or the NeoPixel strip.

Also Serial.print()ing the command variable and the derived integer may also reveal something.
Additionally your int upd_X_LED(String command) should/must return an int value. So if you add return DarbieLED;/return AndrewLED; to the end of the respective functions, you also get feedback whether the command was "translated" correctly.

It's superfluous as AUTOMATIC is the default mode.
For more info look here
https://docs.particle.io/reference/firmware/photon/#system-modes

Finally, for better style use indentation and change this

Adafruit_NeoPixel Andrew_strip(Andrew_PIXEL_COUNT, Andrew_PIXEL_PIN, Andrew_PIXEL_TYPE);
Adafruit_NeoPixel Darbie_strip(Darbie_PIXEL_COUNT, Darbie_PIXEL_PIN, Darbie_PIXEL_TYPE);

The extra assignment only produces overhead.