Compilation error - Help needed

Im coding a messaging system for my screen, serial, or web UI.

I want to pass a string ("like brightness up") and the current 'integer' value of brightness.

For the life of me seem impossible...
Can you help me find what im doing wrong?

#include <stdio.h>
#include <string.h>

//uint8_t       brightness = 50;
int       brightness = 50;


void brightnessDown(){
        if (brightness>0) brightness --;

// this will not compile

        char tmp[] = "Brightness Down";
        // char tmp2 = brightness;
        char tmp2 = brightness+0; // tip i saw somewhere
        char tmp2 = (char) brightness+0; // same result
        char tmp2[] = (char) brightness;
        char tmp2 = (const char) brightness;
        i tried all the wrong sugar to get this to work...

// this does not want to compile        
        strcat(tmp,tmp2);
        //  showDisplay(&tmp);
        //  showDisplayln(tmp);

// this compiles
        Serial.print("brightness: ");
        Serial.println(brightness);

// this will not compile
        // char bri = (char) brightness;
        //showDisplay(bri);
        //  showDisplay(strcat("brightness:",bri));  

        FastLED.setBrightness(brightness);
}

void showDisplay(char *txt)
{
     lcd.print(txt);
    Serial.print(txt);  
    Heltec.display->clear();
 
    Heltec.display->setTextAlignment(TEXT_ALIGN_LEFT);
    Heltec.display->setFont(ArialMT_Plain_10);
    Heltec.display->drawString(0, 0, txt);

}

// This works

void whatever(int x){
...
     case 7:
       currentPalette = RainbowColors_p;  
       showDisplay("Palette: RainbowColors_p");  
       break;
}

Hello snarkycode
Post your entire sketch, well formated, with comments and in so called code tags "</>" to see how we can help.

Have a nice day and enjoy coding in C++.

this works and i can narrow down the issue trying to cast a int to char... this always breaks...

        char tmp2[]= "  ";// = (const char) brightness;
        strcpy(tmp2, tmp); // works
        strcpy(tmp2, brightness); // will not work (casting, or point/address refering neither)
        strcat(tmp,tmp2); // works like strcpy

brightness is an int variable
int is short for "integer", so strcpy (short for "string copy") makes no sense at all.
You could use "itoa" ("int to ASCII") to convert an int to a string.

I'd like a like to the somewhere.

1 Like

it worked and you thought me something new, double like!

for once ibm helps
https://www.ibm.com/docs/en/zos/2.2.0?topic=functions-itoa-convert-int-into-string

DECIMAL didnt compile so i also learned about this!

1 Like

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