arduino pong clock sure 2416 and ds1307

Hi people, I know I’m boring sometimes but I have a big problem and I’m stopped near the solution.

I’ve post the full code of this famous clock.

I would like to add a little funzion: add second near the minute.

This is the code that I added

void invaders()
{
  cls();
  byte hours = rtc[DS1307_HR];
  byte mins = rtc[DS1307_MIN];
  byte second = rtc[DS1307_SEC];
  
  //loop to display the clock for a set duration of SHOWCLOCK
  for (int show = 0; show < SHOWCLOCK ; show++) {

    gettime(); //get the time from the clock chip

    flash_seconds();

    if (button_checks())
    {
      return;
    }

    //update the clock if this is the first run of the show clock loop, or if the time has changed from 
    //what we had stored in mins and hours vars.
    if ( show == 0 || (mins != rtc[1] ) ) {  

      //udate mins and hours with the new time
      mins = rtc[1];
      hours = rtc[2];
      second = rtc[3];       [color=red]<== I THINK HERE IS THE PROBLEM !![/color]
      
      char buffer[8];

      itoa(hours,buffer,10);
      //fix - as otherwise if num has leading zero, e.g. "03" hours, itoa coverts this to chars with space "3 ". 
      if (hours < 10) {
        buffer[1] = buffer[0];
        buffer[0] = '0';
      }

      //update the display
      ht1632_putchar(9,  1, buffer[0]);
      ht1632_putchar(15, 1, buffer[1]);

      plot (21,3,1); //top point
      plot (21,5,1); //bottom point

      itoa (mins, buffer, 10);
      if (mins < 10) {
        buffer[1] = buffer[0];
        buffer[0] = '0';
      }

      ht1632_putchar(23, 1, buffer[0]);
      ht1632_putchar(29, 1, buffer[1]);  
    
    
    itoa(second,buffer,10);
      //fix - as otherwise if num has leading zero, e.g. "03" hours, itoa coverts this to chars with space "3 ". 
      if (second < 10) {
        buffer[1] = buffer[0];
        buffer[0] = '0';
      }   
      ht1632_puttinychar(36, 3, buffer[0]);
      ht1632_puttinychar(40, 3, buffer[1]);  
      
      }

so the problem is that the second remain stopped and never change. I would like that every one second it change !!!

if I change :

second = rtc[DS1307_SEC];

second change when the minute is update.

I become crazy

Why it doesn’t change every time that the buffer change ?

What is rtc[1] or rtc[2] ?

Thanks in advance

Daniel

(this version is with INVADERS )

invaders with second.txt (53 KB)

  //update the clock if this is the first run of the show clock loop, or if the time has changed from 
    //what we had stored in mins and hours vars.
    if ( show == 0 || (mins != rtc[1] ) ) {

This looks like this may be the problem, you want to update also when the seconds ( rtc[DS1307_SEC]) has changed, not just when the minutes (rtc[1]) has changed.

pseudocode:

if firstTime || minutesHaveChanged || secondsHaveChanged

rtc[1] is probably/hopefully the same as rtc[DS1307_MIN], in which case it would be "better" to code: rtc[DS1307_MIN] instead of rtc[1] ...

John

I supposed that was an update problem but can I resolve changing min with sec ??

danielb:
I supposed that was an update problem but can I resolve changing min with sec ??

Why don’t you post the code that represents your attempt to understand me and we will go from there? I have a hard time understanding very specifically your question in english.

On first post there is the full code of this clock

Now in INVADER FUNCTION the time is showed

HH:MM

I would like that the clock show

HH:MM ss

I hope that I answer your question

No, sorry, the original post still has code that says if ( show == 0 || (mins != rtc[1] ) ) {

I suggested you change that line. Change it according to how you understood my suggestion, and then post back what it looks like. Then I will understand whether you understand :)

johncc: I suggested you change that line. Change it according to how you understood my suggestion, and then post back what it looks like. Then I will understand whether you understand :)

If you need even more hint,

    if ( show == 0 || (mins != rtc[1] || ___?????????????????????__ ) ) {

I will try to make your step smaller and smaller if necessary, but will not take the final step for you. For that you will [u]eventually[/u] need to actually [u]think[/u] and actually write [u]code[/u]. Post back with the changed code if you have error you can't fix or it still doesn't work the way you want?

Sorry if you feel I'm being hard on you but part of it is simply because of problems with our different language. :)

Cheers, John

Thanks for your answer
I’ve just tryed this code without success

   //what we had stored in mins and hours vars.
    if ( show == 0 || (mins != rtc[1] || (second !=rtc[3]) ) ) {  

      //udate mins and hours with the new time
      mins = rtc[1];
      hours = rtc[2];
      second = rtc[3];

What's the problem, looks perfect to me from here.

danielb:
Thanks for your answer
I’ve just tryed this code without success

   //what we had stored in mins and hours vars.

if ( show == 0 || (mins != rtc[1] || (second !=rtc[3]) ) ) {

//udate mins and hours with the new time
     mins = rtc[1];
     hours = rtc[2];
     second = rtc[3];

What is with the brackets? What happens when you change it to:

if ( show == 0 || mins != rtc[1] || second !=rtc[3] )

Also, I think you are having to guess that rtc[3] contains the seconds value that you want. If I were you I would use rtc[DS1307_HR], rtc[DS1307_MIN], and rtc[DS1307_SEC]

instead of rtc[1,2,3]

      mins = rtc[1];
      hours = rtc[2];
      second = rtc[3];

The indices do not pass the sniff test. I would expect the data to be returned in logical order - hours, minutes, seconds.

PaulS:       mins = rtc[1];       hours = rtc[2];       second = rtc[3];

The indices do not pass the sniff test. I would expect the data to be returned in logical order - hours, minutes, seconds.

Vice versa more likely

Yes I try to guess !

I added

second = rtc[3];

becouse there were

hours = rtc[0];

and mins = rtc [1];

I started writing

mins = rtc[DS1307_SEC] ;

but I didn't understand why it doesn't works

danielb: becouse there were hours = rtc[0]; and mins = rtc [1];

Thats strange, the last code I saw from you said: mins = rtc[1]; hours = rtc[2];

I started writing mins = rtc[DS1307_SEC]; but I didn't understand why it doesn't works

I'm absolutely [u]speechless[/u] about this, LOL.

This would be a good time to cut/paste and post the complete code again, as it is now...

Cheers, John

this is my error

I write here
mins = rtc[DS1307_SEC];

but I write
second = rtc[DS1307_SEC]

this is the code that I used following your suggestion:

void invaders()
{
  cls();
  byte hours = rtc[DS1307_HR];
  byte mins = rtc[DS1307_MIN];
  byte second = rtc[DS1307_SEC];
  
  //loop to display the clock for a set duration of SHOWCLOCK
  for (int show = 0; show < SHOWCLOCK ; show++) {

    gettime(); //get the time from the clock chip

    flash_seconds();

    if (button_checks())
    {
      return;
    }

    //update the clock if this is the first run of the show clock loop, or if the time has changed from 
    //what we had stored in mins and hours vars.
    if ( show == 0 || (mins != rtc[1] || (second != rtc[3]) ) ) {  

      //udate mins and hours with the new time
      mins = rtc[1];
      hours = rtc[2];
      second = rtc[3];
      
      char buffer[8];

      itoa(hours,buffer,10);
      //fix - as otherwise if num has leading zero, e.g. "03" hours, itoa coverts this to chars with space "3 ". 
      if (hours < 10) {
        buffer[1] = buffer[0];
        buffer[0] = '0';
      }

      //update the display
      ht1632_putchar(9,  1, buffer[0]);
      ht1632_putchar(15, 1, buffer[1]);

      plot (21,3,1); //top point
      plot (21,5,1); //bottom point

      itoa (mins, buffer, 10);
      if (mins < 10) {
        buffer[1] = buffer[0];
        buffer[0] = '0';
      }

      ht1632_putchar(23, 1, buffer[0]);
      ht1632_putchar(29, 1, buffer[1]);  
    
    
    itoa(second,buffer,10);
      //fix - as otherwise if num has leading zero, e.g. "03" hours, itoa coverts this to chars with space "3 ". 
      if (second < 10) {
        buffer[1] = buffer[0];
        buffer[0] = '0';
      }   
      ht1632_puttinychar(36, 3, buffer[0]);
      ht1632_puttinychar(40, 3, buffer[1]);  
      
      }
    
    if (scroll_invader (9,-11,49,random(1,4))) {
      return;
    }
    if (scroll_invader (9,49,-11,random(1,4))) {
      return;
    }

    delay(500);
  }
  fade_down();
}

with this code second are always 01 on display

I hope to resolve

Daniel

Many thanks

danielb: this is the code that I used following your suggestion:

byte hours = rtc[DS1307_HR];
  byte mins = rtc[DS1307_MIN];
  byte second = rtc[DS1307_SEC];

Good!!

      //update the clock if this is the first run of the show clock loop, or if the time has changed from 
    //what we had stored in mins and hours vars.
    if ( show == 0 || (mins != rtc[1] || (second != rtc[3]) ) ) {  

      //udate mins and hours with the new time       mins = rtc[1];       hours = rtc[2];       second = rtc[3];



Not Good!!

this is how i think

there is a loop and this loop change mins on display if rtc[1] is different DS1307_MIN

so

when inside the loop DS1307_MIN NOT EQUAL rtc[1] it change mins

this happening each minute.

I must change this loop and change second on display every second

I think in this way that I don't need to check each minute becouse it check HH and MM and at 59 second change minute ( I think )

what I should do ?

many thanks

Daniel

[1] and [2] and [3] are wrong, Everywhere rtc[]

You need to use [DS1307_HR], [DS1307_MIN], [DS1307_SEC] instead.

Everywhere.

    if ( show == 0 || (mins != rtc[______] || (second != rtc[_______]) ) ) {  

      //udate mins and hours with the new time
      mins = rtc[_______];
      hours = rtc[________];
      second = rtc[_______];

There may but other problems, but you need to do this.

Cheers, John

   //update the clock if this is the first run of the show clock loop, or if the time has changed from 
    //what we had stored in mins and hours vars.
    if ( show == 0 || (mins != rtc[DS1307_MIN] || (second != rtc[DS1307_SEC]) ) ) {  

      //udate mins and hours with the new time
      mins = rtc[DS1307_MIN];
      hours = rtc[DS1307_HR];
      second = rtc[DS1307_SEC];
      
      char buffer[8];

      itoa(hours,buffer,10);
      //fix - as otherwise if num has leading zero, e.g. "03" hours, itoa coverts this to chars with space "3 ". 
      if (hours < 10) {
        buffer[1] = buffer[0];
        buffer[0] = '0';
      }

      //update the display
      ht1632_putchar(9,  1, buffer[0]);
      ht1632_putchar(15, 1, buffer[1]);

      plot (21,3,1); //top point
      plot (21,5,1); //bottom point

      itoa (mins, buffer, 10);
      if (mins < 10) {
        buffer[1] = buffer[0];
        buffer[0] = '0';
      }

      ht1632_putchar(23, 1, buffer[0]);
      ht1632_putchar(29, 1, buffer[1]);  
    
    
    itoa(second,buffer,10);
      //fix - as otherwise if num has leading zero, e.g. "03" hours, itoa coverts this to chars with space "3 ". 
      if (second < 10) {
        buffer[1] = buffer[0];
        buffer[0] = '0';
      }   
      ht1632_puttinychar(36, 3, buffer[0]);
      ht1632_puttinychar(40, 3, buffer[1]);  
      
      }
    
//    if (scroll_invader (9,-11,49,random(1,4))) {
//      return;
//    }
//    if (scroll_invader (9,49,-11,random(1,4))) {
//      return;
//    }

    delay(500);
  }
  fade_down();
}

NOW WORKS !! ( and now I have understand the problem )

the only thing I must comment the code after the clock becouse the refresh was not every 1 second.

no problem becouse I don’t want this code.

Many thanks

Daniel