Real time Clock passing global variables
GrantmcF
Posts: 30
I'm still new at this and haven't gotten the hang of passing variables yet. I have modified a RTC object I found on the object exchange to use 3 buttons and display on a serial LCD. Everything works fine when I run it on one cog. I have tried to modify it to run on 2 cogs with display and setup in the primary cog and the time keeping functions in the 2nd cog. It works ok until I try to write the setup data to the global variables with this instruction, rtc.setDatetime(month, day, year, dow, hour, minute, second) I know I'm not passing the variables between the cogs properly, but every configuration I have tried has choked. I have tried many variations base on the examples in the programming and lab manuals but I'm apparently missing something. Attached is the code without the mess from all my attempts. If anyone can show me what I'm doing wrong it would be greatly appreciated.
Comments
For your RTC setup this simply means you send the time related data with set to the e.g. clock object then instruct it to write the data to the RTC. You can also move the dta array to the top level object and tell the child object its location. This would remove the need for get/set methods.
A variation which shows the background loop doing other stuff and checking command periodically (about 8 times/sec).
This is a really awkward way to do this, but I tried to change as little of your original code as possible.
I didn't change the file names so don't extract it to the same folder as your original files.
I added the address of hour to the start method of "RTC_new_cog".
Here's the new start method of the child object.
I added these constants to keep track of which byte to use for which value.
Here's the main loop of the child object.
Since the top object just had one call to the RTC object, I changed the call to be to the child object instead. This way two different cogs wont try to access the RTC at the same time which would cause errors.
Here's the added method to the child object.
All these methods in the child object are no longer needed since the variables in the top object are automaically updated.
The code compiles, but I don't have a DS1302 to test it with.
As I mentioned, this is really awkward. Hopefully seeing your own code modified to have the child object write to the variables of the top object will help you understand the way this all works and you can get this code to do what you want.