How to make blinking a shape with U8GLIB ?

Hi all,
I'm currently working on a dcf77 clock with a ssd1322 (256x64), a RTC DS1337 and an arduino uno. Everything works well with the u8glib (thanks Oliver !!! :sunglasses:).
The 'void draw()' display the hours, two dots, the minutes, two dots again and the seconds (see attached image). I want to make blinking the two dots between the minutes and the seconds twice per second (0,5 seconds on and 0,5 seconds off every seconds update).
The dots are made with 2 u8g.drawDisc.
I tried several things but no way, i can't seem to make it work :angry:
How can i do it ?

Thanks in advance

Hi

You need two different draw procedures: One which draws the dots and one which does not draw the dots. Additionally: You need two different "picture loops" in which the two different draw procedures are called. In your main loop you alternativly execute the two picture loops.

Of course you can optimize this by using a argument for the draw() procedure.

Pseudo code:
loop()
first picture loop
call draw_without_dots
delay(500)
second picture loop
call draw_with_dots
delay(500)

Or something like this:
is_dot = 0
loop()
is_dot = 1 - is_dot
picture_loop
draw(is_dot)
delay(500)

Oliver

BTW: Nice project and picture. Thanks for sharing.

Thanks for the reply Oliver :wink:
Unfortunately if i use a delay in the loop (or anywhere in the code) the fluidity scrolling turn bad :angry:
Here's the simplified code i made to have a good fluidity :

int outbreak

  • void setup*
  • set RTC time(sec, mins, hours, etc...) // RTC initialisation*
  • outbreak == sec*
  • void loop*
  • read RTC time(sec, mins, hours, etc...)*
  • if (sec == outbreak) { // condition to launch the picture loop*
  • //picture loop*
  • draw()*
  • }*
  • void draw*
  • display stuff...*
  • outbreak = sec + 1 // last lines of the draw procedure*
  • if (outbreak == 60) outbreak = 0*

After several tries i found this way have a clean and regular fluidity for the seconds display increment.
However i tried your solution to use 2 differents draw procedures but without the delays, it works but fluidity is less regular, the dots blinks but just on/off at the second increment...
Maybe i must change the way to launch the picture loop ?

Hi

the dots blinks but just on/off at the second increment...

You could change to a half second timer. In fact i think it is better to use a timer which is based on "millis()" instead of your RTC. You sould only sync with the RTC once per day. Otherwise it will may loose precision.

Maybe i must change the way to launch the picture loop ?

Yes

Additionally, i suggest that you include a flag to mark, whether you executed the picture loop or not. I think you currently redraw the screen too often:

  void loop
    read RTC time(sec, mins, hours, etc...)
    if (sec == outbreak && is_drawn == 0 ) {  // condition to launch the picture loop
      is_drawn = 1;
      //picture loop
      draw()
    }

Oliver