Hi there...
I am looking for the easiest way to copy an existing byte array value, that I successfully print on the serial monitor, to another array for later use.
I am printing the right values using:
The best way i have found to compare is to set up an array with the values u want to match with then when u bring ur serial data in set it up in a if statement and compare it there look at my last post with code on fingerprint scanner with uart communication post the way i set it up should help you out
Arrch:
Use a for loop or strcpy if it's null terminated.
I am having errors with the strncpy command....
char temp1[5];
byte dht11_dat[5];
Serial.print(dht11_dat[2], DEC); // I am getting this correctly
Serial.print(".");
Serial.print(dht11_dat[3], DEC); // I am getting this correctly
strncpy (temp1,&dht11_dat[0],1) // cannot compile error in converting byte to char
Serial.print(temp1);
Please let me know how to copy as an integer or string the values... I am using the DHT11 sensor and I am trying to build a sketch that works without delay.
I need the variables so that I can use them every time I want.
Can someone also tell me how can I declare an array that is used in a function for public use?
nathanas:
Can you please give me the code line that makes that happen? I don't know any of what you say...
strncpy expects a pointer to a character that is assumed to be in an array. Since you have dh11_dat as a pointer to a byte (that is part of an array), you need to type cast it into a char pointer when you passing it into strncpy.
So from &dht11_dat[0] you remove the redundancy to make it dht11_dat and then type cast it into a char pointer instead of byte pointer: (char*) dht11_dat
strcpy() copies a C string (byte or char array) and puts a terminating zero at the end.
strncpy() copies without putting a terminating zero at the end.
strncpy() lets you copy into an existing C string, to replace some characters.
strcpy() would mess that up.
You would do fine to use a while-loop to make your array copy. Then you would know how it works.
Now I need a byte stored in a specific place in an array to be converted to integer.
What, exactly is in this array? Are there characters stored in the array? If so, and the character represents a numeric digit, simply subtract '0' from the value to get the digit ('8' - '0' = 8).
If not, then the value is already a (less than) int-sized value, so just store it in an int.
I figured that out at the time you posted...
It was pretty simple, but had beeen programming for 8 hours last night.
As soon as I woke up it took me about 20 minutes to find out my problem. And last night I'd been struggling for over 2 hours!
Programming can mess your brain up!