New to arduino need help with Error

I'm new to programming Arduino so I have no idea what I'm doing. I am trying to set up an led strip to slowly fad through colors and I want to be able to define the RGB separately and just add 1 every loop down the strip but I have no idea what I'm doing and am getting an expected primary-expression before error. and have no idea what it means

#include <FastLED.h>

#define DATA_PIN     2
#define NUM_LEDS    60
#define R 0
#define G 0
#define B 0


CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}

void loop() {
    for(int i=0; i<NUM_LEDS; i++){
        leds[i] = CHSV(R, G, B,);
        FastLED.show();
        delay(50);
        R + 1
        G + 1
        B + 1
    }
}

Full Error

Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

C:\Users\ME\Documents\Arduino\sketch_sep05a\sketch_sep05a.ino: In function 'void loop()':

sketch_sep05a:18:23: error: expected primary-expression before '(' token

         leds[i] = CHSV(R, G, B,);

                       ^

sketch_sep05a:18:32: error: expected primary-expression before ')' token

         leds[i] = CHSV(R, G, B,);

                                ^

sketch_sep05a:6:11: error: expected ';' before numeric constant

 #define G 0

           ^

C:\Users\ME\Documents\Arduino\sketch_sep05a\sketch_sep05a.ino:22:9: note: in expansion of macro 'G'

         G + 1

         ^

exit status 1

expected primary-expression before '(' token



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Say what ? :thinking:

    R + 1
    G + 1
    B + 1

:woozy_face:

ya no idea what im doing

Welcome to the forum

        R + 1
        G + 1
        B + 1

This is not the way to add 1 to a variable
There are several ways to do it

X++;
X = X +1;
X+=1;

Also

    leds[i] = CHSV(R, G, B,);

too many commas

Changed the code now it is not giving me the error but it is not updating the value of R

#include <FastLED.h>

#define DATA_PIN     2
#define NUM_LEDS    60
int R = 1;
int G = 1;
int B = 1;

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}

void loop() {
    for(int i=0; i<NUM_LEDS; i++){
        leds[i] = CHSV(R, G, B);
        FastLED.show();
        delay(5);
        R++;
    }
}

To add to what @LarryD said.

#define means the following is a constant and cannot be changed. Declare the variables so that they may be changed if you want to increment them later.

Here is your code so that it will compile.

#include <FastLED.h>

#define DATA_PIN     2
#define NUM_LEDS    60

// variables declared so that they may be changed
// declared as byte since the max value is 255
byte R = 0;
byte G = 0;
byte B = 0;


CRGB leds[NUM_LEDS];

void setup()
{
   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}

void loop()
{
   for (int i = 0; i < NUM_LEDS; i++)
   {
      leds[i] = CHSV(R, G, B); // remove the extra comma
      FastLED.show();
      delay(50);

      // properly increment a variable
      R += 1;
      G += 1;
      B += 1;
   }
}

Kudos for a very well formed first post. Full code posted in code tags plus the entire error message. You probably have no idea how rare it is for a new user to make such a great first post. Big thumbs up.

Thank you so much I'm so used to programming in python and am not used to this at all.

You are using the Hue/Saturation/Value color model with Saturation and Value both 0. That will always produce BLACK, regardless of what Hue of BLACK you select.

Try setting Saturation and Value to the midpoint (128) so you can see the change in Hue.

Or you could use CRGB() instead of CHSV(). That will allow you to see the Red intensity go up.

Your best troubleshooting tool is the serial print. Use serial prints to follow execution of the code and monitor variable values. See below where I start the serial port (Serial.begin(9600);) and add serial prints to watch the value of R. I also slow execution down (delay(500);) so the serial port does not flood. I do see the value of R changing so something else is going on so that you do not see the changes. @johnwasser has the answer to that.

#include <FastLED.h>

#define DATA_PIN     2
#define NUM_LEDS    60
// int data type wastes a byte for each variable
byte R = 1;
byte G = 1;
byte B = 1;

CRGB leds[NUM_LEDS];

void setup()
{
   Serial.begin(9600);
   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}

void loop()
{
   for (int i = 0; i < NUM_LEDS; i++)
   {
      Serial.print("value of R = ");
      Serial.println(R);
      leds[i] = CHSV(R, G, B);
      FastLED.show();
      delay(500);
      R++;
   }
}

Output:

11:00:25.245 -> value of R = 1
11:00:25.735 -> value of R = 2
11:00:26.266 -> value of R = 3
11:00:26.755 -> value of R = 4
11:00:27.245 -> value of R = 5
11:00:27.772 -> value of R = 6
11:00:28.259 -> value of R = 7
11:00:28.787 -> value of R = 8
11:00:29.272 -> value of R = 9
11:00:29.762 -> value of R = 10
11:00:30.290 -> value of R = 11
11:00:30.778 -> value of R = 12

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.