Create a library with CRBG as a parameter function

Hi everyone,

I’m using FastLED.h

To simplify my program, I want to create a library called LedsHorloge.h in which one I’ll run a bit of code to light up my led strip.

I’m newby in C++

This is my code in Arduino :

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

#define LED_PIN     6
#define NUMBER_LEDS    32
#define BRIGHTNESS  100
#define LED_TYPE    WS2812B
#define VITESSE_JAUGE 150 // Delay milliseconds



int tour = 0 ; // Compte le nombre de tour dans le loop
int pinButton = 8; // Pin qui déclenche la fonction "Jauge"
boolean flag = false ;

LedsJauge jauge(LED_PIN); // This is the object I create 

void setup() {

    delay( 3000 ); // power-up safety delay
    FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUMBER_LEDS).setCorrection( TypicalLEDStrip ); // Initialisation de la bande de leds

    FastLED.clear(); // Fonction d'initialisation, encore mal connue

    pinMode(pinButton, INPUT_PULLUP) ;
    InitBandeLeds(); // Eteint toutes les leds si elles sont allumées;  // Applique la valeur HSV définie dans la variable "leds"

void loop() { 

  // tant que le bouton n'est pas activé, le drapeau reste false
  if ( digitalRead(pinButton) == LOW ){
    flag = true ;

  // lorsque le drapeau devient true on rentre dans la condition
  if (flag){
      if ( tour < NUMBER_LEDS ){  tour += 1;  } // A chaque loop la variable est incrémenté de 1
      jauge.Jauge(tour, NUMBER_LEDS, BRIGHTNESS, &leds);; 
      FastLED.delay(1000 / UPDATES_PER_SECOND);
      delay(VITESSE_JAUGE); // régle la vitesse d'allumage des leds


// Fonction qui éteint le bandeau de leds
void InitBandeLeds(){
    for( int i = 0; i < NUMBER_LEDS; i++) {
        if ( tour - i >0 ){
          leds[i] = CHSV( 0, 0, 0) ;

This is my header called LedsHorloge.h

#ifndef LedsHorloge_h
#define LedsHorloge_h

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

class LedsJauge
 LedsJauge(int pin);
 // A chaque tour une led supplémentaire de la jauge est allumée
 void Jauge(int tour, int numberLeds, int brightness, CRGB* ledTable);
 int _pin;


This is my source code called LedsHorloge.cpp

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

LedsJauge::LedsJauge(int pin)
 _pin = pin;

void LedsJauge::Jauge(int tour, int numberLeds, int brightness, CRGB* ledTable)
    for( int i = 0; i < numberLeds; i++) {
        if ( tour - i >0 ){
          ledTable[i] = CHSV( 100, 187, brightness) ;

When I run this code I get the arduino IDE :

D:\Programmation\Arduino\libraries\libraries\JaugeLED/LedsHorloge.h:16:8: note: void LedsJauge::Jauge(int, int, int, CRGB*)

   void Jauge(int tour, int numberLeds, int brightness, CRGB* ledTable);


D:\Programmation\Arduino\libraries\libraries\JaugeLED/LedsHorloge.h:16:8: note:   no known conversion for argument 4 from 'CRGB (*)[32]' to 'CRGB*'

exit status 1
no matching function for call to 'LedsJauge::Jauge(int&, int, int, CRGB (*)[32])'

I don’t know how to make a pointer on the object CRGB leds[NUMBER_LEDS];

Thank you very much if someone can help me !


jauge.Jauge(tour, NUMBER_LEDS, BRIGHTNESS, leds);

Thanks a lot, it is working ! :)

I guess it is because the object CRGB is already a pointer, otherwise it is working but I don't understand why.

Thanks again gfvalvo

Yes, it has been a convention since the early days of 'C' that the name of an array (of any type) can be treated as a pointer to the first element of that array.

Why is the declaration and implementation of a class called LedsJauge in files called LedsHorloge.h and LedsHorloge.cpp?

The name of the files should match the name of the class being defined/implemented.

There are numerous violations of this “rule”. For example, both ‘SPIClass’ and ‘SPISettings’ are declared in ‘SPI.h’.

And, in fact, 'SPI' is NOT a class but an object of type 'SPIClass'.

Thank you gfvalvo for your last information !

And good observation of PaulS, I gonna modify this mistake.