I am using a Mega 2560 with a micro SD card logger and a RTC. I have snipped two programs from the internet. One is for the RTC and the other is for the data logger. I have married these tow for my sketch to run my program.
These two programs seem to work well except the data logger will not record the "mv" or "percent" value. Only 0 0 is recorded after the date and time. See attached PDFs. I have attached my code.
I would appreciate and help in figuring out why I cannot data log the "mv" and "percent" values.
I am using an external +5 high on Pin 7 to request the the moment for the data logger to record the date, time, mv and percent.
I added a println command for mv and percent. As you can see on one of the PDFs img_4508 the mv and percent are indeed printed line by line, but no in the data logger line showing date, time and again 0 0 for mv and percent.
I would appreciate any help or suggestions to point me in the right direction for fix this issue.
You have const variables at the top, you then create LOCAL variables with the same name in your code.
Don't make VARIABLEs const, this makes them read only. DONT create variables inside code with the same name as you may confise yourself as to what variable you are updating.
Same problem. You have multiple mv variables declared. The one that gets a value (the float) goes out of scope before you use it so you print the global one (int) which is always zero.
JerryHawkins:
So how should I change my code? Please advise. Thank you.
Use the "find" search tool for each variable that you've defined that is giving problem output (like the zeros you are complaining about...). You will be able to see the duplicate definitions. Delete either the global one, if it's not used elsewhere, or edit the local ones to remove the declaration, e.g.
'int someInteger = 1;'
becomes
'someInteger = 1;'
Spend some time on it, don't just flounder for 5 minutes and come back here immediately. Go research, "C/C++ variable scope".