SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By brian25
#163090
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.
By Mee_n_Mac
#163121
Once again you ask something of a cryptic question and that's why you don't get many responses. I'm going to interpret your question the following way.
i want to read the pins
What pins ? I will guess you'll be reading some digital inputs, whose values are then constrained to be either 0 (LOW) or 1 (HIGH).
and ouput like this 10111
This is my guess as to what the above means. You want to store and later send the ASCII characters that correspond to LOWs and HIGHs of the pins sampled. For example if the digital pins, D0 - D4, read as 10111, then you want to store in a string and later send the following (hex) values 0x31, 0x30, 0x31, 0x31, 0x31 and then the end of string character.
how to put a value of int or byte in a string
Actually if you're reading some pins, you want to put some characters representing the Boolean values of the pins read into a string, aka a character array, with each characters position in the array corresponding to the pin read.

So declare a char array at the start of your code. Note the array must be sized to stored the end of string character, '\0', as well as your data. 5 pins means 6 characters.
Code: Select all
char string[6];
I've forgotten whether the declaration above automatically puts the end of string character in the last character or whether you have to do that in your code.

Then read the pins and store their char equivalents into the array.
Code: Select all
for(i=0; i<5; i++){
  if(digitalRead(i) == LOW){
    string[i] = '0';
  }
  else{
    string[i] = '1';
  }
}
I strongly expect there are alternate and better ways to do the above (assuming I've not made some syntax error) but the above is the most explanative way I could come up with. Let's see the more compact ways !!

http://arduino.cc/en/Reference/String