Go Down

Topic: arduino pong clock sure 2416 and ds1307 (Read 1 time) previous topic - next topic

danielb

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:

Code: [Select]
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

johncc



this is the code that I used following your suggestion:
Code: [Select]
byte hours = rtc[DS1307_HR];
  byte mins = rtc[DS1307_MIN];
  byte second = rtc[DS1307_SEC];

Good!!
Code: [Select]
      //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!!

danielb

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

johncc

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

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

Everywhere.

Code: [Select]
    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

danielb

Code: [Select]
   //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

johncc


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

Hey that's great!  Post a video on Youtube or something, it looks like it has a very nice case...

Quote

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.


How long was it taking to refresh the Seconds? 

You don't want the animated invader icon?  Maybe you could leave it in if you commented the delay(500) instead of the invader stuff.
Try it!

Cheers!
John

danielb

Tomorrow i'll post a video. I wpuld like tu put the data where is the invaders. With your suggestion there will be not problem. I hope !

danielb

As I promise to you here the video

Thank you. Tomorrow I'll post the code with the day and month.

In id function I added

|| day != rtc[DS1307_DAY]
But I'm not sure that is needed

Here the video

http://www.youtube.com/watch?v=ICXgGSv0LRg&feature=youtube_gdata_player


danielb

If function

I think that probably I don't need to add that
|| day != rtc[DS1307_DAY]

becouse it recall gettemp function by
|| sec != rtc[DS1307_SEC] that change each secon ?

Is it wrong ??

Next days I'll ask you about scroll text... I hope it will be possible !

Go Up