FastLED Error

I am trying to use the FastLED library but am having a problem. Here is my code:

#include <Snake.h>

#define LED_PIN 13
#define NUM_LEDS 64
#define GRID_WIDTH 8
CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2812, LED_PIN>(leds, NUM_LEDS);
}
void loop() {}

Snake.h is a library that I wrote which has #include <FastLED.h>.

The error I am getting is error: expected initializer before 'leds' on CRGB leds[NUM_LEDS];, but I don't see how I am doing anything wrong. If I don't use the Snake library and directly import FastLED.h, I don't get any error, but I need to use the CRGB type in Snake.

make sure you have the right board, it doesn't work on many.

sevenoutpinball:
make sure you have the right board, it doesn't work on many.

I am using an Uno (and have it set correctly in the IDE), but at this point I am just trying to verify/compile the program; I'm not trying to upload it to the board.

Snake.h is a library that I wrote which has #include <FastLED.h>.

You still need to include it in the main sketch also#include <FastLED.h>

Deva_Rishi:
You still need to include it in the main sketch also

#include <FastLED.h>

I still get the same error when I include it in the main sketch.

Post your code.
Post the full error message(s)

Do you by any change have something like

#define CRGB whatever

in Snake.h?

edit

More likely you have forgotten the semicon after a class defintion:

class SomeClass {
...
};
 ^

TheMemberFormerlyKnownAsAWOL:
Post your code.
Post the full error message(s)

The error message:

In file included from C:\Users\gabem\Desktop\JonahGift\JonahGift.ino:1:0:
C:\Users\gabem\Documents\Arduino\libraries\FastLED/FastLED.h:14:21: note: #pragma message: FastLED version 3.003.003
 #    pragma message "FastLED version 3.003.003"
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
JonahGift:10:6: error: expected initializer before 'leds'
 CRGB leds[NUM_LEDS];
      ^~~~
C:\Users\gabem\Desktop\JonahGift\JonahGift.ino: In function 'void setup()':
JonahGift:70:36: error: 'leds' was not declared in this scope
   FastLED.addLeds<WS2812, LED_PIN>(leds, NUM_LEDS);
                                    ^~~~
C:\Users\gabem\Desktop\JonahGift\JonahGift.ino:70:36: note: suggested alternative: 'gets'
   FastLED.addLeds<WS2812, LED_PIN>(leds, NUM_LEDS);
                                    ^~~~
                                    gets
exit status 1
expected initializer before 'leds'

The sketch:

#include <FastLED.h>
#include <Snake.h>

#define LED_PIN 13
#define NUM_LEDS 64
#define GRID_WIDTH 8

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2812, LED_PIN>(leds, NUM_LEDS);
}

void loop() {}

The header (Snake.h):

#ifndef Snake_h
#define Snake_h

#include "Arduino.h"
#include <FastLED.h>

class Snake {
    public:
    Snake(int initial_r, int initial_c, CRGB c_body, CRGB c_body_fade, 
    CRGB c_tail, CRGB c_tail_fade, int num_links);
    
    // Called on the head of the snake, which calls move on itself
    int moveHead(int dir, int width, CRGB* leds);

    // Checks if the head of this snake has intersected the other snake
    // If so, and this snake isn't faded and it intersected the other snake's tail,
    // this player wins. If the snake is faded, keep going. If the snake isn't faded 
    // and is not touching the tail, fade it.
    // returns 0 if no collision
    // returns 1 if a body collision or faded tail collision
    // returns 2 if an unfaded tail collision
    int checkCollision(Snake* other_snake);

    // Checks if any links of this snake is intersecting the other snake
    bool checkIntersection(Snake* other_snake);
    void fadeColor(bool fade, int width, CRGB* leds);
    bool isFaded();
    void setColor(int width, CRGB* leds);
    void reset(int reset_r, int reset_c);

    private:
    // checks if any of this snake's links are at location (check_r, check_c)
    // returns 0 if no links are at the location
    // returns 1 if a body link is at the location
    // returns 2 if the tail link is at the location
    int isIntersecting(int check_r, int check_c);
    
    // moves the link to a new position and sets the color
    int move(int new_r, int new_c, int width, CRGB* leds);
    
    int r, c;
    int last_move;
    CRGB color_cur, color_reg, color_fade;
    bool faded;
    Snake* next;
}
#endif

The source:

#include "Snake.h"

Snake::Snake(int initial_r, 
             int initial_c, 
             CRGB c_body, 
             CRGB c_body_fade, 
             CRGB c_tail, 
             CRGB c_tail_fade, 
             int num_links) {
    
    r = initial_r;
    c = initial_c;
    last_move = -1;
    faded = false;
    if(num_links != 0) {
        color_cur = c_body;
        color_reg = c_body;
        color_fade = c_body_fade;

        next = new Snake(r-1, c, c_body, c_body_fade, c_tail, c_tail_fade, num_links-1);
    }
    else {
        color_cur = c_tail;
        color_reg = c_tail;
        color_fade = c_tail_fade;
        next = nullptr;
    }
}

void Snake::reset(int reset_r, int reset_c) {
    r = reset_r;
    c = reset_c;
    color_cur = color_reg;
    faded = false;
    last_move = -1;

    if(next != nullptr) {
        next->reset(reset_r-1, reset_c);
    }
}

int Snake::moveHead(int dir, int width, CRGB* leds) {
    if(dir == last_move) {
        return -1;
    }
    int next_r = r, next_c = c;
    if(dir == 0) { // Up
        if(r == 0) { // loop from the top
            next_r = width-1;
        } else {
            next_r--;
        }
    }
    else if(dir == 1) { // Right
        if(c == width-1) { // loop from the right
            next_c = 0;
        } else {
            next_c++;
        }
    }
    else if(dir == 2) { // Down
        if(r == width-1) { // loop from the bottom
            next_r = 0;
        } else {
            next_r++;
        }
    }
    else if(dir == 3) { // Left
        if(c == 0) {
            next_c = width-1;
        } else {
            next_c--;
        }
    }

    last_move = dir;

    move(next_r, next_c, leds);
}

int Snake::checkCollision(Snake* other_snake) {
    int collision = other_snake->isIntersecting(r, c);
    if(collision == 0) {
        return 0;
    }
    if(collision==2 && !faded) {
        return 2;
    }
    if(collision==2 && faded) {
        return 1;
    }
    if(collision==1) {
        if(!faded) {
            fadeColor(true);
        }
        return 1;
    }
    return -1;
}

bool Snake::checkIntersection(Snake* other_snake) {
    int intersect = other_snake->isIntersecting(r, c);
    if(intersect != 0) {
        return true;
    }
    else {
        if(next == nullptr) {
            return false;
        }
        return next->checkIntersection(other_snake);
    }
}

void Snake::fadeColor(bool fade, int width, CRGB* leds) {
    if(fade == faded) {
        return;
    }
    color_cur = (fade) ? color_fade : color_reg;
    faded = fade;
    leds[r * width + c] = color_cur;
    if(next != nullptr) {
        next->fadeColor(fade);
    }
}

bool Snake::isFaded() {
    return faded;
}

void Snake::setColor(int width, CRGB* leds) {
    leds[r * width + c] = color_cur;
    if(next != nullptr) {
        next->setColor(width, leds);
    }
}



int Snake::isIntersecting(int check_r, int check_c) {
    if(check_r == r && check_c == c) {
        return (next != nullptr) ? 1 : 2;
    }
    else {
        return (next != nullptr) ? next->isIntersecting(check_r, check_c) : 0;
    }
}

int Snake::move(int new_r, int new_c, int width, CRGB* leds) {
    if(next == nullptr) {
        leds[r * width + c] = CRGB::Black;
        r = new_r;
        c = new_c;
        leds[r * width + c] = color_cur;
        return 0;
    }
    int last_r = r, last_c = c;
    r = new_r;
    c = new_c;
    leds[r * width + c] = color_cur;
    return next->move(last_r, last_c, width, leds);
}
    Snake* next;
}
#endif

Yep, missing semicolon.

And @oqibidipo has it!

See how easy it is when you post code?

oqibidipo:
Do you by any change have something like

#define CRGB whatever

in Snake.h?

edit

More likely you have forgotten the semicon after a class defintion:

class SomeClass {

...
};
^

You're completely right, I fixed that and am getting a different error, but one that I can handle. Thank you very much!