strings

I have a data logger and want to add time to the log.

what I do is to watch to see when the motor is running, thereby starting the timer.
once the motor stops, I stop the timer and then take total running seconds.

I create a string in one section of program to log to my SD card, but this time is in a different part.

How can I declare a string to be global so that I can add this to the write string ?

I am thinking it would be less memory intensive to have a string that is

01:22:54

this shows seconds : minutes : hours

than to have each of the three variables as global and adding them to my string for data logging.

I am thinking it would be less memory intensive to have a string that is

9 bytes, instead of three scalar variables that are one byte each.

I don't understand that logic.

How can I declare a string to be global

char string[10];

outside of any function.

PaulS:
9 bytes, instead of three scalar variables that are one byte each.

I don't understand that logic.

char string[10];

outside of any function.

logic ? who tried to bring logic into this ???
just to understand....
byte second
byte minutes
byte hour
would take less space than

putting these into a string and passing that string globally ?

just to understand....
byte second
byte minutes
byte hour
would take less space than

putting these into a string and passing that string globally ?

The second, minutes, and hour variables use three bytes. The string representation of the time uses 9 bytes. In my state, 3 is less than 9. That might be different in New Jersey.

Why are you bothered about saving 6 bytes - it hardly matters to the SD Card.

Saving data in human readable format has a lot going for it.

...R

I think the 'lesson' is valuable..

but I agree with Robin2.. human readable has it place, and makes it easier for us 'noobs' to understand as well.

counting time to data log in one section of code, for use in the data write loop. so I have to use a global in some form to pass the information from where I do the calculating to where it is written to the SD card

I am just starting with time and datalogging so am bumping against the edges of my knowledge and believe me, it is a pretty small box I am working in.

May I offer that I asked because I don't know. Often one can make such an assumption, but it seems that in some cases, that is not the basis of the response.

Besides, if I have 3 times, actually 3 numbers, 2 digits each, that represent times. seconds, minutes, hours, they are not scalar, the are integers. AFAIK

Paul said "9 bytes, instead of three scalar variables that are one byte each. I don't understand that logic."

I guess my question is much deeper. A scalar variable, such as 17:23:03
vs three byte variables 17 , 20 and 03

does the one scalar, when declared as a global, does it use more memory than three variables of all bytes ?

it would seem to me you have the variable name, or address, then the stored value
3 names and 3 stored values vs 1 name and a larger stored value.

May I offer that reading the references has lead me in circles and brought me here.

http://playground.arduino.cc/Code/DatatypePractices
in reading this, it would seem that what Paul is implying is that you take one byte for the address, then one byte for each place, in my case 6 numbers and 2 letters, to have 9 bytes.

dave-in-nj:
I guess my question is much deeper. A scalar variable, such as 17:23:03
vs three byte variables 17 , 20 and 03

does the one scalar, when declared as a global, does it use more memory than three variables of all bytes ?

I would deal with the part I high-lighted first by asking "does it matter?"

I then looked at Wikipedia and it seems there are 4 uses of scalar and I can't figure which you mean.

It seems to me that 17:23:03 requires a string variable rather than an integer - and 17,23,03 (i.e. CSV, comma separated variables) would probably be more readily parsed in programs such as Excel.

I would store the time value in SRAM in whatever form made it easiest to develop and maintain the program - including the possibility of converting it to a number of seconds since some base date. A lot depends on what "sums" you want to do with the date/time value. For example if you need to count the number of days or find the last day of a month it is easier if the values are separate.

But I would probably write the data to the SD Card as a string because it would be very easy to check it just by reading the file in a text editor.

...R

I guess my question is much deeper. A scalar variable, such as 17:23:03

17:23:00 is not a scalar variable. 17 might be held in a scalar variable, occupying one byte of SRAM. The same applies to 23 and 00, for a total of 3 bytes.

Or, the values could be converted to a string, "17:23:00" (which implies a terminating NULL) that is 8 characters (plus the NULL) long, needing 9 bytes to store it.

does the one scalar, when declared as a global, does it use more memory than three variables of all bytes ?

I hope that it is now clear that this question is meaningless.

PaulS:
17:23:00 is not a scalar variable. 17 might be held in a scalar variable, occupying one byte of SRAM. The same applies to 23 and 00, for a total of 3 bytes.

Or, the values could be converted to a string, "17:23:00" (which implies a terminating NULL) that is 8 characters (plus the NULL) long, needing 9 bytes to store it.
I hope that it is now clear that this question is meaningless.

Scalar was defined and a number. it seems that I think 0 to 9. like my minutes and hours.
a colon however, is also a number : 58 in DEC, 072 in OCT, and 00111010 in binary.

seems the word scalar is not self explanatory.

to jump past the confusion I just made sec/min/hr as global and got that to work fine. Added the colon in the string with all the other parts to write to the SD card.