Need help with CRGB or FastLed? (resolved)

Hello everyone.
I need your help with a flame simulation, I have this error:
"Compilation error: cannot convert 'CRGB' to 'uint8_t {aka unsigned char}' for argument '1' to 'uint8_t qsub8(uint8_t, uint8_t)'"
Thanks in advance.

As a guess the problem is in the sketch that you have not posted ...

What type is CRGB? Just cast it?

you made an error in the line which calls qsub8.
But we don't see that line.
We need to see a complete code and the complete error message from the compiler.

1 Like

The FastLED color commands in their simplest form look like one of these two...

led[x] = CRGB::Blue;
or
led[x] = CRGB (0, 0, 255);

My guess is you are trying to pass the array "led[x]" to a function that is not ready for an array.

1 Like

Thank you for your interest

here is the code

//Libraries
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
#define LED 3 // led3 en patte 6 
#include <Wire.h>
SoftwareSerial mySerial(10, 11); // RX, TX

int busy = 8;
int com=0; // commubication entre arduino
#include <FastLED.h>//library a telecharger en zip
//Constants
#define NUM_STRIPS 1
#define NUM_LEDS 144 // max144 
#define NUM_LEDSf1 72 // long fire Front 72
#define BRIGHTNESS 255// power bright >>>>>>>>> Lumiere 
#define LED_TYPE WS2812B
#define COLOR_ORDER RGB
#define FASTLED_ALLOW_INTERRUPTS 0
#define FASTLED_INTERRUPT_RETRY_COUNT 1
#define FRAMES_PER_SECOND 60
#define COOLING 90 // 20-100 more=short fire
#define SPARKING 120 // 50-200 more=no blink

// ======== VARIABLE modifiable ========
int POS_trimR = 44; // <<< Pos led Trim REAR/Pneu arriere 44 for Did3D delorean / 45OR46 for Eaglemoss model
int rate=400; // Rate of New Samples 0 Fast >> 9999 long
int ns=22; // Number of samples random 0 to 22 
int psmoke=58;


// ========
bool gReverseDirection = false;

// leds[xt1+5]=qsub8(leds[xt1+5],(50)); // reduit la lumiere Ă  50 de ce led
// tableau flammes
uint8_t Fsprite1[5][3] = {{50,1,1},{156,15,0},{255,144,0},{255,52,0},{81,5,0}};
//uint8_t Fsprite1[5][3] = {{100,0,0},{0,100,0},{0,0,100},{237,96,16},{57,13,7}};
//uint8_t
int cpr=0;
int cv=0;
int cb=0;

//int fRGB[144][3]; 
float fx[15];
float flum[15];
float flu=0;
float fx1[15];
float flum1[15];
float vx=2;
int la=0;
int dbf= 0; // Pos Start Fire Front

int pn1=2; // position pneu1
int bsmok=0;
int f=0;
int col=0;
int anit=0;
int xt1=0;
int lf1=0;
int xf=7;
long tmp=0;
long ts1=0;
long tscl=0;
long tf1=0;
long resettime=0;
int x=0;
int rf=250;
int vf=200;
int bf=30;
int cr=0;
int ctf=0;
int animf=0;
int animt=0;
int animfa=0;
int anima=0;
int clavier=0;
long tmpanim=0;
float lbang=10;
float bds=0.3;
int animb=0;
long tb1=0;
long clin=0;
int bang=0;
int bout1=0;
int a=1;
int animglace=0;
int tbusy=55;
int ret=0;
int ret2=0;
int sound=1;
int antr=0;
int mod=0;
int standby=0;
int scene=1;
int tsc=0;
int standsc=0;
int standby1=0;
int choix=1;
long tmpr=0;
long tmchx=0;
long tsmok=0;
int asmoke=0;
int bturbo=0;
int ledc =0;
int order=0;
int animfs=0;
float ps=0;
//Parameters
const int stripPin  = 3; // pin 3 de la carte nano
int nlsmok=72;

//Objects
CRGB leds[NUM_LEDS];

void setup() {

  Wire.begin(); // commencé 12c communication 
 //son
  Serial.begin (9600);
  mySerial.begin (9600);
  mp3_set_serial (mySerial);  //set softwareSerial for DFPlayer-mini mp3 module 
  delay(1);  //wait 1ms for mp3 module to set volume
  mp3_set_volume (30);       // value 0~30
  mp3_set_EQ(0);
randomSeed(analogRead(0)); // randomize le random

delay(100);
// == Bouton pin A0
//pinMode(2, INPUT); // bouton Scene
pinMode(2, INPUT_PULLUP); 
//Serial.begin (9600);
FastLED.addLeds<LED_TYPE, stripPin, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(  BRIGHTNESS );
FastLED.clear();// efface toute les led off
// leds[i].r=255 // led au rouge 255 ou R=leds[i].r (POUR GET COULEUR .r .g ou .b )

// == rempli le tableau ===
for (int i = 0; i < 14; i++)
  {
     fx[i]=i*5+7; flum[i]=0;
  }
for (int i = 0; i < 14; i++)
  {
     fx1[i]=i*5+7; flum1[i]=0;
  }
  
analogWrite (4,0);FastLED.clear();FastLED.show();
//Serial.println(f);Serial.println(flum[f]);
//mp3_play(94);delay(32000);
delay(100);
mod=0; // MOD START ==
}
void loop() // ===================================== DEBUT ==================================== 
{
DEBUT:
FastLED.show();  
tmp=millis();
tbusy=digitalRead(busy); // busy= 1 si libre
bout1=digitalRead(2);//_ lecture bouton
//Serial.println(bout1);
if ((bout1==0)and(antr==0)) {antr=1; mod++;standby=0;standby1=0;FastLED.clear();FastLED.show();if (mod>1){mod=0;}Serial.println(mod);} // bouton appui
if (bout1==1){antr=0;}
//Serial.println("dd");

if (mod==0) // ======== MOD 0 = standby =====
{
//test led com

    if (standby==0) // bruit demarage system
    {
      standby=1;mp3_play(13);

      order=22;trans(); //eteint tout:

      order=35;trans();order=20;trans();delay(700); // switch on
      order=40;trans();delay(50); // tb switch on
      order=50;trans();delay(50); // plaf switch on
      order=30;trans();order=60;trans();delay(50); // ch switch on
      order=15;trans();delay(50); // warn switch on
      order=1;trans();delay(10);
    } 
    tbusy=digitalRead(busy); 
    
    if ((tbusy==1)&&(standby==1))
    {
    if ((tmp>tmchx+20)&&(tbusy==1)) // === ROUTINE STAND BY ==== 
    {
       tmchx=tmp;choix=random(1,ns);
       if (random(rate)==1){mp3_play(choix);delay(10);}
       if (random(3200)==1){mp3_play(89);order=1;trans();delay(10);} // phare on
       if (random(4000)==1){mp3_play(87);order=1;trans();delay(2600);order=10;trans(); } // phare demar pas 
       if (random(4000)==1){mp3_play(74);order=10;trans();delay(10);}// phare off
       if (random(20000)==1){alltout();delay(50);mod=1;}// lance trip  
      }
    }
}

if (mod==1) // ======== MOD 1 = Demarre Time Trip  =====
{

if (standby1==0) {standby1=1;standby=0;tmpanim=0;mp3_play(89);order=1;trans();delay(500);order=16;trans();} // lancer mod 1
if ((standby1==1)&&(digitalRead(busy)==0)) {goto DEBUT;}
if ((standby1==1)&&(digitalRead(busy)==1)) {standby1=2;mp3_play(99);bturbo=0;animf=0;animt=0;bsmok=0;animfa=0;animglace=0;animb=0;bang=0;anima=0;asmoke=0;}

if (tmp>tmpr+50){tmpr=tmp;tmpanim=tmpanim+50;} //Serial.println(tmpanim); // compteur de temp anim
if ((tmpanim>11000)&&(tmpanim<22500)) {asmoke=1;}
if ((tmpanim>22500)&&(tmpanim<24000)) {animf=0;animt=1;animfa=0;asmoke=0;}
if ((tmpanim>24000)&&(tmpanim<24500)) {animf=1;animt=0;animfa=0;}
if ((tmpanim>24700)&&(tmpanim<29500)) {animf=1;animt=0;animfa=0;animfs=0;}
if ((tmpanim>29500)&&(tmpanim<49000)) {animf=0;animt=0;animfa=1;}
if ((tmpanim>56400)&&(tmpanim<58000)) {animf=0;animt=0;animfa=0;animglace=0;animb=1;anima=0;}// bang
if ((tmpanim>58000)&&(tmpanim<94000)) {animf=0;animt=0;animfa=0;animglace=1;animb=0;bang=0;}


if ((tmpanim>94000)&&(tmpanim<95000)) {standby1=0;FastLED.clear();FastLED.show();mod=0;standby=1;bturbo=0;asmoke=0;bsmok=0;animf=0;animt=0;animfa=0;animglace=0;animb=0;bang=0;anima=0;}


  
  if (animf==1) // === Flamme Did rapid ===
 {
    //if (animfs==0){animfs=1;order=21;trans();}
    FireDid();
 } 
 if (animt==1) // === TURBO ==
 {
  if (bturbo==0){bturbo=1;FastLED.clear();FastLED.show();order=21;trans();}
   if (tmp>ts1+5) 
   {
    ts1=tmp;
    xt1=0 ; turbo();// appelle turbo1
    xt1=POS_trimR; turbo();// appelle turbo1
   }
 } 
  if (animb==1) // == BANG  =    =========
 {
   if (tmp>tb1+1) 
   {
     tb1=tmp;
     if (bang==0){bang=1;lbang=41;bds=2;}
     if ((bang==3)&&(lbang==41)){order=23;trans();}
     lbang=lbang-0.45;
     if (lbang <2){lbang=41;bds=2;bang++;if (bang>3){bang=0;animb=0;lbang=1;};}
     bangstar();
     
   }
 }
 
 if (animfa==1) // == Flames ARRET ||||| ==========
 {
   if (anima==0){anima=1;vx=5;order=22;trans();delay(5);order=10;trans();} //tout eteindre}
   if (tmp>tf1+50) 
   {
     tf1=tmp;
     vx=vx-0.1; if (vx<0.1){vx=0;}
     for (int f = 0; f < 14; f++) 
     {
      xf=fx[f];flu=flum[f]; flame();// appelle flame
      flum[f]=flum[f]-0.6;
      fx[f]=fx[f]+vx; if (fx[f]>70){fx[f]=pn1;flum[f]=255;}
     }

      // ======= Flame Arriers =======
      for (int f = 0; f < 14; f++) 
      {
        xf=fx1[f];flu=flum1[f]; flame();// appelle flame
        flum1[f]=flum1[f]-0.6;
        fx1[f]=fx1[f]+vx; if (fx1[f]>70){fx1[f]=POS_trimR;flum1[f]=255;}
      }
   }
 } 
 if (asmoke==1) // = = = == = = roule = = = =
  {
    if (bsmok==0){bsmok=1;ps=5;tsmok=0;}
    tsmok++; 
    if (tsmok>ps){ledscroold();tsmok=0;ps=ps-0.04;if (ps<0){ps=0;}}
    if (random(60)==1)
      {
      leds[0].setRGB(0,0,0);leds[1].setRGB(12,10,3);leds[2].setRGB(8,6,3);
      if (random(2)==1){leds[0].setRGB(0,0,0);leds[1].setRGB(8,6,2);leds[2].setRGB(7,5,2);}      
 //     leds[0].setRGB(0,0,0);leds[1].setRGB(15,13,4);leds[2].setRGB(9,7,4);
 //     if (random(2)==1){leds[0].setRGB(0,0,0);leds[1].setRGB(10,8,3);leds[2].setRGB(9,7,4);}
      }
  } 


   
  if (animglace==1) // == glace ARRET ||||| ==========
 {
   if (anima==0){anima=1;vx=5;}// retour
   if (tmp>tf1+50) 
   {
     tf1=tmp;
     vx=vx-0.07; if (vx<0.1){vx=0;}
    
     for (int f = 0; f < 14; f++) 
     {
      xf=fx[f];flu=flum[f]; glace();// appelle glace
      flum[f]=flum[f]-0.1;
      fx[f]=fx[f]+vx; if (fx[f]>70){fx[f]=pn1;flum[f]=255;}
     }

      // ======= glace Arriers =======
      for (int f = 0; f < 14; f++) 
      {
        xf=fx1[f];flu=flum1[f]; glace();// appelle flame
       flum1[f]=flum1[f]-0.1;
        fx1[f]=fx1[f]+vx; if (fx1[f]>70){fx1[f]=POS_trimR;flum1[f]=255;}
      }
   }
 }   


  }

}


// ___________------------- F O N C T I O N ----------____________

// >>>>>> FONCTION scrooling droite >>>>>>
void ledscroold(void)  
{
   for (int i = 72; i > 0; i--) 
   {
      leds[i]=leds[i-1];
   }
}

// ****** Fonction reacteur ****
void turbo(void)
{
  anit=random(4);
  if (anit==0){leds[xt1].setRGB(62,130,255);leds[xt1+1].setRGB(214,255,255);leds[xt1+2].setRGB(255,244,255);leds[xt1+3].setRGB(255,85,155);leds[xt1+4].setRGB(109,52,14);leds[xt1+5].setRGB(39,6,0);}
  if (anit==1){leds[xt1].setRGB(214,255,255);leds[xt1+1].setRGB(255,244,255);leds[xt1+2].setRGB(255,85,155);leds[xt1+3].setRGB(109,52,14);leds[xt1+4].setRGB(39,6,0);leds[xt1+5]=qsub8(leds[xt1+5],(50));}
  if (anit==3){leds[xt1].setRGB(255,85,155);leds[xt1+1].setRGB(109,52,14);leds[xt1+2].setRGB(39,6,0);leds[xt1+3]=qsub8(leds[xt1+3],(100));leds[xt1+4]=qsub8(leds[xt1+4],(100));leds[xt1+5]=qsub8(leds[xt1+5],(50));}
} 

// ****** Fonction flamme SPRITES ****  ||||| |||| -|-|
void flame(void)
{
  lf1=random(0,100);
  for (int i = 0; i < 5; i++)
  {
   leds[constrain((xf+i),0,72)].setRGB(constrain(255-lf1-(i*50)-(255-flu)+(leds[xf+i].r/3),0,255),constrain(150-lf1-(i*50)-(255-flu)+(leds[xf+i].g/3),0,255),constrain(40-lf1-(i*50)-(255-flu)+(leds[xf+i].b/3),0,255));
  }
   for (int i = 5; i > 0; i--)
  {
   leds[constrain((xf-i),0,72)].setRGB(constrain(255-lf1-(i*50)-(255-flu)+(leds[xf-i].r/3),0,255),constrain(150-lf1-(i*50)-(255-flu)+(leds[xf-i].g/3),0,255),constrain(40-lf1-(i*50)-(255-flu)+(leds[xf-i].b/3),0,255));
  }
}
// ****** Fonction Glace SPRITES ****  =-_-=-_-_-=-
void glace(void)
{
  lf1=0;
  for (int i = 0; i < 5; i++)
  {
   leds[constrain((xf+i),0,72)].setRGB(constrain((59-lf1-(i*20))-(255-flu),0,255),constrain((60-lf1-(i*20))-(255-flu),0,255),constrain((60-lf1-(i*20))-(255-flu),0,255));
  }
   for (int i = 5; i > 0; i--)
  {
   leds[constrain((xf-i),0,72)].setRGB(constrain((59-lf1-(i*20))-(255-flu),0,255),constrain((60-lf1-(i*20))-(255-flu),0,255),constrain((60-lf1-(i*20))-(255-flu),0,255));
  }
}  

void FireDid() // **************** FIRE Did3D ************* 
{
// Array of temperature readings at each simulation cell
  static uint8_t heat[NUM_LEDSf1-1];

  // Step 1.  Cool down every cell a little
    for( int i = 0; i < NUM_LEDSf1; i++) {
      heat[i] = qsub8( heat[i],  random8(0, ((COOLING * 10) / NUM_LEDSf1) + 2));
    }
  
    // Step 2.  Heat from each cell drifts 'up' and diffuses a little
    for( int k= NUM_LEDSf1 - 1; k >= (2); k--) {
      heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
    }
    // Step 3.  Randomly ignite new 'sparks' of heat near the bottom
    if( random8() < SPARKING ) {
      int y = random8(7);
      heat[y] = qadd8( heat[y], random8(100,255) );// 160-255
    }
 
    if( random8() < SPARKING ) {
      int y = POS_trimR + random8(5);
      heat[y] = qadd8( heat[y], random8(100,255) );
    }

    // Step 4.  Map from heat cells to LED colors
    for( int j = 0; j < NUM_LEDSf1; j++) {
      CRGB color = HeatColor( heat[j]);
      int pixelnumber;
      if( gReverseDirection ) {
        pixelnumber = (NUM_LEDSf1-1) - j;
      } else {
        pixelnumber = j;
      }
      leds[pixelnumber] = color;
    }
}


void clrs() // _____Fonction effece ecran uniquement sur Putty ________
{
  Serial.write(27);       // ESC command
  Serial.print("[2J");    // clear screen command
  Serial.write(27);
  Serial.print("[H");     // cursor to home command
}

void bangstar(void) // === bang bleu  ==
{
 
  for (int i = 0; i < (lbang/2); i++)
  {
    leds[22+i].setRGB( constrain(255-((i+2)*(300/(lbang/2))),0,255),constrain(255-((i+2)*(300/(lbang/2))),0,255),constrain(255-((i+2)*(255/(lbang/2))),0,255) );
  }
  for (int i = 0; i < (lbang/2); i++)
  {
    leds[22-i].setRGB( constrain(255-((i+2)*(300/(lbang/2))),0,255),constrain(255-((i+2)*(300/(lbang/2))),0,255),constrain(255-((i+2)*(255/(lbang/2))),0,255) );
  }
}

void trans()
{
  Wire.beginTransmission(9); // transmit to device #9
//Serial.println("4");
  Wire.write(order);          // demande 0 allumé
//Serial.println("5");
  Wire.endTransmission();    // stop transmitting 
//Serial.println("6");
}

void alltout()
{
      order=22;trans(); //eteint tout:
      order=35;trans();order=20;trans();delay(700); // switch on
      order=40;trans();delay(50); // tb switch on
      order=50;trans();delay(50); // plaf switch on
      order=30;trans();order=60;trans();delay(50); // ch switch on
      order=15;trans();delay(50); // warn switch on
}

and the full error message :slight_smile:

Code_BASE_Did3D_1.ino: In function 'void turbo()':
Code_BASE_Did3D_1.ino:336:200: error: cannot convert 'CRGB' to 'uint8_t {aka unsigned char}' for argument '1' to 'uint8_t qsub8(uint8_t, uint8_t)'
Code_BASE_Did3D_1.ino:337:137: error: cannot convert 'CRGB' to 'uint8_t {aka unsigned char}' for argument '1' to 'uint8_t qsub8(uint8_t, uint8_t)'
Code_BASE_Did3D_1.ino:337:174: error: cannot convert 'CRGB' to 'uint8_t {aka unsigned char}' for argument '1' to 'uint8_t qsub8(uint8_t, uint8_t)'
Code_BASE_Did3D_1.ino:337:210: error: cannot convert 'CRGB' to 'uint8_t {aka unsigned char}' for argument '1' to 'uint8_t qsub8(uint8_t, uint8_t)'

exit status 1

Compilation error: cannot convert 'CRGB' to 'uint8_t {aka unsigned char}' for argument '1' to 'uint8_t qsub8(uint8_t, uint8_t)'

please identify this library.
Exact name, Author, Version - so we can find it in the library manager.

If it is not available in the library manager - tell us the exact location where we can find it.

DFPlayer_Mini_mp3.zip (14.2 KB)

The code you posted is not the code giving the error.

qsub8 takes two uint8_t.
your leds[] is an array of the structure CRGB not a single uint8_t.

so when you want to substract 50 from a color within your CRGB::leds[], you have to give a information on what member (color?).

for example this compiles:


#include <FastLED.h>
#define NUM_LEDS 144
CRGB leds[NUM_LEDS];

int anit = 0;
int xt1=0;

void debug() {
  if (anit == 1) {
    leds[xt1].setRGB(214, 255, 255);
    leds[xt1 + 1].setRGB(255, 244, 255);
    leds[xt1 + 2].setRGB(255, 85, 155);
    leds[xt1 + 3].setRGB(109, 52, 14);
    leds[xt1 + 4].setRGB(39, 6, 0);
    //leds[xt1 + 5] = qsub8(leds[xt1 + 5], (50)); // BUG: CRGB is a structure, not an uint8_t 
    leds[xt1 + 5].r = qsub8(leds[xt1 + 5].r, (50)); // but you can use one color 
  }
}


void setup() {
  Serial.begin(115200);
  anit = 1;
  debug();
}

void loop() {
  // put your main code here, to run repeatedly:

}

read mor about CRGB

https://fastled.io/docs/struct_c_r_g_b.html

Back from vacation, thank you it works.
Thanks to everyone who responded.