Arduino Lib Help!.

Thread Starter

brian25

Joined May 13, 2013
37
how to put a value of int or byte in a string

SendSMS(byte sim_phonebook_position, char *message_str)

i want to read the pins and ouput like this 10111(1 if high and 0 if low)
but this part (char *message_str) only accept string.
 

odinhg

Joined Jul 22, 2009
65
Could you use itoa()? It gives you a null-terminated string from any integer in the base of your choice.

http://www.cplusplus.com/reference/cstdlib/itoa/

I think it is implemented in the Arduino libraries. If not, maybe you could use sprintf()?

Rich (BB code):
char stringBuffer[6]; 

itoa(InputVariable, stringBuffer, 2);

SendSMS(sim_phonebook_position, stringBuffer)
 

sirch2

Joined Jan 21, 2013
1,037
I think you can sprintf it to your string

Rich (BB code):
sprintf(stringbuffer, "%0b", byteVariable);
but I would amke your stringbuffer variable 8 characters long, or use snprintf.

That assumes you are reading all the pins in one go as a register. If you are checking them individually then you can set your string characters directly, one at a time.
 
Top