InnitButton and ASCII conversion

Hello,
I'm new in C programming (used to use Delphi). I want to change the text of a button using a variable

int red_value = 255;
void setup{
do some other stuff
b_red.initButton(&tft, 40, 40, 60, 40, WHITE, RED, BLACK, "255", 2);
b_red.drawButton;
}
void loop
do some stuff
red_value= getRed();
b_red.initButton(&tft,40,40,60,40,WHITE, RED, BLACK,red_value, 2);
b_red.drawButton;
do other stuff

Lets say that getRed returns "145" then i get some very strange signs in the button but not "145".
I looked in the refernece to change the int into a ASCII string, but cannot find it. Is there a function in C that convert this? In Delphi it is simple X= str(red_value).
Thanks for the help

what's b_red ??

Don't post snippets (Snippets R Us!)

if you want to convert a number to a string, you can use itoa() (and will need a buffer to store the text)

I just want the result of a funtion (let's say int red=145, but I need to have "145") into the InitButton function who requires an ASCII string? In Delphi this is a minor detail. In C(Arduino) it is hopeless complicated.

Jacques_verl:
I just want the result of a funtion (let's say int red=145, but I need to have "145") into the InitButton function who requires an ASCII string? In Delphi this is a minor detail. In C(Arduino) it is hopeless complicated.

Too bad. Have you noticed that you're coding a machine that has less memory than some calculators? You're using a library, so any accusations of complexity should maybe fall on the authors of the library. Did you pay or contribute anything to the library, or to the Arduino project? Probably not.

If you know of a simpler way of programming an Arduino, there is nothing stopping you from doing it. It's fully open source hardware and software.

Since you didn't post the source for 'getRed()' how are we supposed to guess why it doesn't work?

There is a string data type in arduino. Have a look to the sample sketches in arduino IDE under string.
An alternative is to use a characters array or pointer.

char mychars[] = “145”;
Or
String mystring =“145”;
Or
Char* mystring =“145”;

Cheers

Jacques_verl:
Hello,
I'm new in C programming (used to use Delphi). I want to change the text of a button using a variable

int red_value = 255;

void setup{
do some other stuff
b_red.initButton(&tft, 40, 40, 60, 40, WHITE, RED, BLACK, "255", 2);
b_red.drawButton;
}
void loop
do some stuff
red_value= getRed();
b_red.initButton(&tft,40,40,60,40,WHITE, RED, BLACK,red_value, 2);
b_red.drawButton;
do other stuff



Lets say that getRed returns "145" then i get some very strange signs in the button but not "145".
I looked in the refernece to change the int into a ASCII string, but cannot find it. Is there a function in C that convert this? In Delphi it is simple X= str(red_value).
Thanks for the help

I believe you want to do this:
string myString= String(red_value);

abdelhmimas:
I believe you want to do this:
string myString= String(red_value);

assuming initButton() knows how to handle the String class and does not just deal with a const char*...

You are right

Thanks for the answeer. I see the problem now: the Button Class needs a const char apperently. Will need to define the button myself.
Thanks

or just build the buffer with itoa() as suggested in #1

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