tcas271
tcas271

Reputation: 31

AVR ATMega169P LCD display using C++

I am trying to display something to the LCD screen on an ATMega 169P microcontroller. When using C, I am able to use this code:

char str[50];
int value = 100;
str = sprintf(str, "some text %d", value);
LCD_puts(str);

and it will display fine. LCD_puts is a method given to us by my teacher. However, I am trying to use C++ for my assignment, and I cannot get LCD_puts() to work. I've used sprintf and snprintf and I receive the following compiler error when using snprintf. The code I am using is below also. (Apologies for the formatting, I cannot post pictures).

char str[100];
int rpm = 100; //Genaric value

snprintf(str, 100, '%d in',rpm);
LCD_puts(str);

invalid conversion from 'char*' to 'unint8_t*' {aka unsigned char*}'[-fpermissive]

I don't think my exact code is required, I only need to know why this error would be caused and if there is a C++ function that is the equivalent to sprintf that I could use. I will post my exact code if needed however.

Upvotes: 0

Views: 663

Answers (1)

seansy
seansy

Reputation: 105

You are attempting to store an unsigned char array into a signed char array. Either declare str as unsigned char:

unsigned char str[100];

or cast str in the argument as unsigned char:

snprintf((uint8_t*)str, 100, '%d in',rpm);

In this case uint8_t and unsigned char are equivalent.

Upvotes: 1

Related Questions