Help with led colour change

Hello, I have an Arduino Nano RP2040 Connect board.

I was trying for the first time to implement some things in it to test out and learn about Arduino.

I have a problem with a function listed below. If I understand correctly, for me to be able to change the colour of the LED on my board I have to get the colour value first and then write the desired colour value to the pins but, I have a problem getting the colour.
I would appreciate it if someone could help me with the code. Thank you in advance.

// Function to handle color changes
void onColorChange() {
  if (led) { // Only update color if the LED is ON
    uint8_t red, green, blue;

    // Extract RGB components from the CloudColor object
    color.getValue(red green blue); // Get the red, green, and blue values

    // Set the RGB LED to the specified color
    analogWrite(redPin, red);
    analogWrite(greenPin, green);
    analogWrite(bluePin, blue);

    // Debug output
    Serial.print("Color changed: R=");
    Serial.print(red);
    Serial.print(" G=");
    Serial.print(green);
    Serial.print(" B=");
    Serial.println(blue);
  } else {
    Serial.println("LED is OFF. Cannot change color.");
  }


Does this line compile? I would have thought that commas would be needed to separate the 3 variables.

@m1x_er After you fix the compile error, try moving the colour bars, they will change the colour or if allowed enter HSB or HEX values. That way your onColorChange event will fire.

The following message is displayed when compiling with comas added

error: no matching function for call to 'CloudColor::getValue(uint8_t&, uint8_t&, uint8_t&)'
     color.getValue(red, green, blue); // Get the red, green, and blue values

the variables are of type "unit8_t"

 uint8_t red, green, blue;

Hello, I solved the problem.

Problem was that I was trying to get the value with getValue, similarly to getCloudValue, which can't directly output data into variables.

Solution:

...
    // Extract RGB components from the CloudColor object
    Color currentColor = color.getCloudValue(); // Get the corrent red, green, and blue values
    currentColor.getRGB(red, green, blue);
...

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