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.
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.
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.
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).i want to read the pins
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.and ouput like this 10111
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.how to put a value of int or byte in a string
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.
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.
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 !!