Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i convert a uint32_t to a char* type

Hello i am using an Arduino UNO with an adafruit shield to display score values but the function used to display scores only accepts char* values and the score itself can occupy up to 6 digits(000,000 to 999,999). i have tried using sprint() but i have had no luck since the screen will flicker like crazy. i believe the problem to be that chars only hold a certain number of bytes that could not fit a 32 bit int but i would think their is a way around this. draw text is the function used by the shield to drawstuff on the screen with input being char*, color code, size, x pixel, y pixel. if anybody can please help me convert between these two types please let me know. also if their are alternatives that would also help me.

my code:

char* textToWrite;
uint32_t currentScore = 0;
uint32_t highScore = 0;
highScore = currentScore;
sprintf(textToWrite,"%d.%d.%d.%d\0", currentScore);//sprint f not working properly right now
drawText(textToWrite, ST7735_WHITE, 1, 100, 10);

i have also tried using:

sprintf(textToWrite,"%u", currentScore);
like image 569
blu Avatar asked Nov 26 '13 16:11

blu


1 Answers

char textToWrite[ 16 ];
uint32_t currentScore = 42;
// as per comment from LS_dev, platform is int 16bits
sprintf(textToWrite,"%lu", currentScore);
like image 164
manuell Avatar answered Nov 16 '22 01:11

manuell