Arduino Lib Help!.

Discussion in 'Embedded Systems and Microcontrollers' started by brian25, Sep 3, 2013.

  1. brian25

    Thread Starter Member

    May 13, 2013
    37
    0
    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.
     
  2. odinhg

    Active Member

    Jul 22, 2009
    65
    15
    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()?

    Code ( (Unknown Language)):
    1.  
    2. char stringBuffer[6];
    3.  
    4. itoa(InputVariable, stringBuffer, 2);
    5.  
    6. SendSMS(sim_phonebook_position, stringBuffer)
    7.  
     
  3. sirch2

    Well-Known Member

    Jan 21, 2013
    1,008
    351
    I think you can sprintf it to your string

    Code ( (Unknown Language)):
    1. 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.
     
Loading...