Could not compile

Hey

I was working on my some code for my Photon, and all of the sudden it won’t compile at all. I have no idea why and can’t seem to find anything wrong with the code. It doesn’t give any specific errors, all it says when I try to verify is “Error: Could not compile. Please review your code.”

Here’s what I’m currently working with that won’t compile.

#include "FastLED/FastLED.h"
FASTLED_USING_NAMESPACE;

#define NUM_LEDS 24
#define DATA_PIN 6
#define CLOCK_PIN 13

// Define the array of leds
CRGB leds[NUM_LEDS];

int colorSet(String command); //This is for the function in the IFTTT cloud

int fadeAmount = 1;
int brightness = 0;
int colorval = 0;

bool breathe;
bool rain;

void setup()
{
    Particle.function("set_color", colorSet);
    
    FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
    FastLED.setBrightness(64);
    for(int i = 0; i < NUM_LEDS; i++)
    {
        leds[i] = 0x000000;
    }
    FastLED.show();
}

void loop()
{ 
    if(breathe == true)
    {
        for(int i = 0; i < NUM_LEDS; i++)
        {
            leds[i] = colorval;
            leds[i].fadeLightBy(brightness);
        }
        FastLED.show();
        brightness = brightness + fadeAmount;
        if(brightness == 0 || brightness == 255)
        {
            fadeAmount = -fadeAmount ;
        }  
        delay(10);
    }
}

int colorSet(String command) // This section is where it checks what has been sent from the cloud. Recipes will get 
{
    if(command == "red")
    {
        breathe = true;
        rain = false;
        colorval = 0xFF0000;
    }
    if(command == "blue")
    {
        breathe = true;
        rain = false;
        colorval = 0x0000FF;
    }
    if(command == "green")
    {
        breathe = true;
        rain = false;
        colorval = 0x00FA9A;
    }
    else return 69;
}

EDIT: It’s currently 11:21 am and I have to work night shift starting at 7:00 pm. I must sleep for the day. If anyone has any helpful advice, it will be appreciated when I wake later. Thanks in advance.

At a guess I would say it is this line.
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
If it a libarary function I would think it goes .
Fastled.whatever( neopixel , data pin ) etc

Strange it looks wrong on the screen but formats right when you copy it.

What IDE are you using? And what FastLED lib version are you using? The one on Particle Build seems to not build at all for the Photon - only for the Core. I’ve pinged the owner of the lib repo to push his latest version with the Photon support incorporated.

One thing you’d need to correct, although this should not cause your code not to build, but it might bodge the execution.

You have not got a return xxx; statement in all your code paths in your colorSet().

maybe like this

int colorSet(String command) // This section is where it checks what has been sent from the cloud. Recipes will get 
{
    if (command == "red")
      ...
    else if(command == "blue")  // you should use else if ()
      ...
    else if(command == "green") // you should use else if ()
      ...
    else                        // otherwise this will also hit with "red" & "blue"
      return -1;     // impossible color on error

    return colorval; // if everything worked, return what we just set
}

@peter_a, the notation with angled brackets is used in C++ for templates in generic programming
http://www.tutorialspoint.com/cplusplus/cpp_templates.htm

The reason why it looks different after copy pasting angled brackets is because that <...> tags are hidden, but when you put them in code formatting (` inline code `)
or

block code

they get displayed, since you told “Discourse” (the forum software) not to interpret tags or such but leave it unaltered.

Hi @Jarmom,

This is totally silly, but there is a bug at the moment in the pre-processor that I haven’t had a chance to fix yet. Can you drop a few empty lines at the top of your file before the include statement? If this fixes it I will be very embarrassed and go fix this bug right away. :astonished:

Thanks,
David

2 Likes

Hi David,

Adding a four blank lines didn’t fix it, so I don’t think that’s the issue!

@ScruffR, thanks for the general code etiquette. I will add those as soon as possible. I am using the FastLED lib built into the WebIDE, but I’m wondering why it won’t compile now, as I had it compiling earlier. My initial coding was done to get it to turn on for Red, Green, Blue, etc, and it compiled fine. Then when I went around to adding a fill_rainbow function, it just stopped working. I don’t think I kept any of the lines around that were from the fill_rainbow function but I might have missed some that would cause it to not compile.

If I need to compile using the Dev IDE, how would I go about adding the FastLED Library to use? I certainly wouldn’t mind installing it and adding the library if I had to so that I could work on this code today.

2 Likes

What version of FastLED are you using?
And are you really targeting a Photon and not a Core?

The current version on Build is v3.1.3 and I can’t get it to build for the Photon.
It just throws

 fatal error: platforms/avr/led_sysdefs_avr.h: No such file or directory
 #include "platforms/avr/led_sysdefs_avr.h"

But v3.1.4 is already on GitHub and just needs pushing online.
See end of the discussion here
https://github.com/focalintent/FastLED-Sparkcore/issues/2

Yeah, I’m using v3.1.3. I couldn’t get any of the fancy examples to upload, like ColorPallete (which I was going to attempt to use for my rainbow effect,) but I started building in the Web IDE when I successfully pushed the Blink program to my Photon. It wasn’t a one off thing, either, since I flashed code maybe 10 times earlier today when I was experimenting with Red and how to get it to work.

I don’t know how or why. I’m certainly not an experienced coder or anything. Until the update is pushed (kind of under a time constraint currently), would you mind directing me to resources that would tell me how to install it for the Dev IDE?

Edit : Must look like I’m crazy, because the Blink program doesn’t flash anymore either, same error you gave me. Interesting…

I have not tried it myself yet, but I'd start with trying it this way:

  1. Go to the GitHub repo and download the ZIP from there
  2. Extract the ZIP
  3. Copy the .h/.cpp files from the firmware sub-folder to a new folder for your project
  4. Create a new .ino file in that folder and copy your project code into it
  5. Change #include "FastLED/FastLED.h" to only #include "FastLED.h"
  6. Start Particle Dev and open the project folder (not the .ino file)
  7. Select your target device
  8. Hit build

If your project has errors and you've got CLI installed, I'd rather go with it for building, since the error output is "better" (at least when I used Dev the last time).

I’ll definitely check it out when I get home here in about an hour. Here’s to hoping that it works out! Would love to share pictures and possibly video of the project when it’s all said and done here on the forums! Thanks for all the help.

1 Like