Offline
Newbie
Karma: 0
Posts: 20
|
 |
« on: April 25, 2012, 04:10:55 pm » |
Hello All I am working on a POV clock that is giving me a hard time in the coding department. I am at a point where I have been able to get data from a RTC breakout board and store the values. I also have been able to assign those values to a predefined character set for the POV. I am able to display the Hours values, the minutes values, and the seconds values. HOWEVER, I can only display them individually and not all at once. I think I am not creating either a string or an array correctly. Here is a part of my sketch that deals with this issue: //Declaring variables. int Hrs = now.hour(); int Mins = now.minute(); int Sec = now.second();
int Time =(Hrs, Min, Sec); //This is just for debugging. Just to see what is being sent to the LED's Serial.println(Time); delay(1000);
Ok, at this point when I put all three values in "int Time" all I get is my seconds value printing out on the serial monitor and on my POV clock. How can I get it to show all individual values. Keep in mind, I am only using the Serial.print command here JUST to see whats being sent to my POV display. Thanks Phillip B.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 0
Posts: 451
I am a amateur.
|
 |
« Reply #1 on: April 25, 2012, 04:30:11 pm » |
Are you trying to concatenate the Hrs, Min, Sec together in an interger? I'm a confused about int Time =(Hrs, Min, Sec); I've never seen this in a code before. Suppose Hrs is 9, Min is 23 and Sec is 56. Do you want to put them together like this: 92356? Please tell me exactly want you want to accomplish with the code you put up, and what Time =(Hrs, Min, Sec); is supposed to do.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #2 on: April 25, 2012, 04:38:11 pm » |
Are you trying to concatenate the Hrs, Min, Sec together in an interger? I'm a confused about int Time =(Hrs, Min, Sec); I've never seen this in a code before. Suppose Hrs is 9, Min is 23 and Sec is 56. Do you want to put them together like this: 92356? Please tell me exactly want you want to accomplish with the code you put up, and what Time =(Hrs, Min, Sec); is supposed to do.
I am trying to make one variable with all 3 parts of the time, Hrs, Mins, Secs. I still haven't figured out how to get the colons in there yet. So if the Hrs = 9, the Mins = 23, and the Sec = 56. I want the Time to = 9:23:56. How do I get that to happen. Also how can I get the predefined colons to show in that same variable too. My POV character set has a colon defined in it.
|
|
|
|
|
Logged
|
|
|
|
|
New Hampshire
Offline
God Member
Karma: 13
Posts: 776
There are 10 kinds of people, those who know binary, and those who don't.
|
 |
« Reply #3 on: April 25, 2012, 04:45:32 pm » |
ints can only stored a single discrete integer value that is 16bits in size. What you want is a string displaying the time in a specific format. sprintf() will allow you to generate a specifically formatted string containing the values you want. Google it for details on it's usage. fyi, it returns a char array (ie c style string).
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #4 on: April 25, 2012, 04:50:15 pm » |
Thanks
I understand how the sprintf() command will work. Is it possible to store all 3 of the time values and the colons as one variable so I can send it out to the POV display? I am only using the serial.print line just to see whats being sent to the POV.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 16
|
 |
« Reply #5 on: April 25, 2012, 04:50:54 pm » |
Maybe you want something like: char Time[10];
sprintf( Time, "%02d:%02d:%02d", Hrs, Mins, Sec );
Serial.println( Time );
The printf formatting code '%02d' means print an integer, zero-padded to 2 digits. E.g. '9' will be printed as '09'
|
|
|
|
|
Logged
|
|
|
|
|
83 - var
Offline
Sr. Member
Karma: 0
Posts: 452
ARDUINO Powa !
|
 |
« Reply #6 on: April 25, 2012, 04:51:23 pm » |
test that ! int Hrs = now.hour(); int Mins = now.minute(); int Sec = now.second();
int Time[3] =(Hrs, Min, Sec); // your tab of int ! String string_time=""; //This is just for debugging. Just to see what is being sent to the LED's
string_time += String(hour); // (or =+ i dont say :s sry) string_time += String(" : "); string_time += String(minute); string_time += String(" : "); string_time += String(seconde);
Serial.println(string_time); delay(1000);
Two solution for you, the int hour and the string our to save or print ! Skizo !
|
|
|
|
|
Logged
|
Un tien vaux mieux que deux tu l'auras !
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #7 on: April 25, 2012, 05:08:55 pm » |
test that ! int Hrs = now.hour(); int Mins = now.minute(); int Sec = now.second();
int Time[3] =(Hrs, Min, Sec); // your tab of int ! String string_time=""; //This is just for debugging. Just to see what is being sent to the LED's
string_time += String(hour); // (or =+ i dont say :s sry) string_time += String(" : "); string_time += String(minute); string_time += String(" : "); string_time += String(seconde);
Serial.println(string_time); delay(1000);
Two solution for you, the int hour and the string our to save or print ! Skizo ! Hey Skizo Thanks for the help but it did not work. I am still getting just the seconds value printing out. Any other suggestions?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #8 on: April 25, 2012, 05:34:31 pm » |
Thanks for the help but I still could not get what I needed. here is the entire code that I am using, so maybe it will be easier to understand. I had help with the code so there are still parts of it I am a bit confused about.
|
|
|
|
« Last Edit: April 26, 2012, 08:19:39 pm by bafill »
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #9 on: April 25, 2012, 06:43:31 pm » |
int Time =(Hrs, Mins, Sec); This is not some sort of concatenation operation. That will just evaluate to Secs. What was wrong with the sprintf idea?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #10 on: April 25, 2012, 07:16:52 pm » |
int Time =(Hrs, Mins, Sec); This is not some sort of concatenation operation. That will just evaluate to Secs. What was wrong with the sprintf idea? Hi Nick I'm glad you chimed in on this. I could not get the sprintf() to work. I kept getting 2 different kinds of errors doing it. One was an invalid conversion from 'int' to 'const char*', and the other was initializing argument 2 of 'int sprintf(char*, const char*, ...)' Heres that bit of code: void loop() {
//Calling time from RTC. DateTime now = RTC.now();
//Declaring variables. int Hrs = now.hour(); int Mins = now.minute(); int Sec = now.second(); sprintf (displayThis, 'Hrs', 'Mins', 'Sec'); delay (1000); } // end of loop
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #11 on: April 25, 2012, 07:29:48 pm » |
Why are you quoting your variables? That's a strange way to do it. More like this: char displayThis [20]; sprintf (displayThis, "%02i:%02i:%02i", Hrs, Mins, Sec); Now you will have to display each byte from displayThis one after the other so the digits appear in sequence.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #12 on: April 25, 2012, 07:56:14 pm » |
Hey Nick
If I do a Serial.println(displayThis); to check what displayThis has in it. It is correct and perfect. Thanks. But excuse my rookie attempts at writing code, but what are the "%2i:" I have only see %d or %02d when writing some C code. Also, will that also show the colons on my POV display if I am able to see them in the Serial monitor?
Thanks again, Phillip B.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #13 on: April 25, 2012, 08:30:42 pm » |
You should be able to find printf on the Net somewhere. Basically %i is for ints, whereas %d is for "decimal" (I think normally short ints). Probably %d would have worked - not that you had that. Also, will that also show the colons on my POV display if I am able to see them in the Serial monitor? If you font has them it should (and the font appears to have them). Just take them out if you don't want them.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #14 on: April 25, 2012, 08:35:40 pm » |
Thank you Nick
I think we got it figured out.
But I have ANOTHER question. I have hooked it up to my Adruino UNO driven POV and tried it. But it didn't look correct. So I tried displaying the original hello word version you gave me but I changed it to show just the number 8. It seems to display more than just an 8 but many other characters. I can't figure out why.
|
|
|
|
|
Logged
|
|
|
|
|
|