\hypertarget{embryo_timer_8edc-example}{\section{embryo\-\_\-timer.\-edc}
}
This example shows the usage of timers in embryo.


\begin{DoxyCodeInclude}
collections \{
   group \{ name: \textcolor{stringliteral}{"main"};
      script \{
         \textcolor{keyword}{public} timer\_cb(val) \{
            \textcolor{keyword}{new} x, y, w, h;
            \textcolor{keyword}{new} buf[32];

            \textcolor{comment}{/* set labels with object info */}
            get\_geometry(PART:\textcolor{stringliteral}{"red\_rect"}, x, y, w, h);
            snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"Timer called %d times."}, val);
            set\_text(PART:\textcolor{stringliteral}{"label1"}, buf)
            snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"Object x: %d  w: %d"}, x, w);
            set\_text(PART:\textcolor{stringliteral}{"label2"}, buf)

            \textcolor{comment}{/* renew the timer */}
            timer(1 / 30, \textcolor{stringliteral}{"timer\_cb"}, val + 1);
         \}
      \}
      parts \{
         part \{ name: \textcolor{stringliteral}{"bg"};
            type: RECT;
            description \{ state: \textcolor{stringliteral}{"default"} 0.0;
               color: 255 255 255 255;
            \}
         \}
         part \{ name: \textcolor{stringliteral}{"label1"};
            type: TEXT;
            description \{ state: \textcolor{stringliteral}{"default"} 0.0;
               color: 0 0 0 255;
               text \{
                  text: \textcolor{stringliteral}{""};
                  font: \textcolor{stringliteral}{"Sans"};
                  size: 12;
                  align: 0.0 0.7;
               \}
            \}
         \}
         part \{ name: \textcolor{stringliteral}{"label2"};
            type: TEXT;
            description \{ state: \textcolor{stringliteral}{"default"} 0.0;
               color: 0 0 0 255;
               text \{
                  font: \textcolor{stringliteral}{"Sans"};
                  size: 12;
                  align: 0.0 0.8;
               \}
            \}
         \}
         part \{ name: \textcolor{stringliteral}{"red\_rect"};
            type: RECT;
            description \{ state: \textcolor{stringliteral}{"default"} 0.0;
               color: 255 0 0 255;
               max: 30 30;
               align: 0.1 0.2;
            \}
            description \{ state: \textcolor{stringliteral}{"default"} 1.0;
               inherit: \textcolor{stringliteral}{"default"} 0.0;
               color: 0 0 255 255;
               max: 50 30;
               align: 0.9 0.2;
            \}
         \}
      \}
      programs \{
         \textcolor{comment}{/* move the red rect back an forth in a loop */}
         program \{ name: \textcolor{stringliteral}{"init"};
            signal: \textcolor{stringliteral}{"load"};
            source: \textcolor{stringliteral}{""};
            action: STATE\_SET \textcolor{stringliteral}{"default"} 1.0;
            transition: SINUSOIDAL 1.0;
            target: \textcolor{stringliteral}{"red\_rect"};
            after: \textcolor{stringliteral}{"loop"};
         \}
         program \{ name: \textcolor{stringliteral}{"loop"};
            action: STATE\_SET \textcolor{stringliteral}{"default"} 0.0;
            transition: SINUSOIDAL 1.0;
            target: \textcolor{stringliteral}{"red\_rect"};
            after: \textcolor{stringliteral}{"init"};
         \}
         \textcolor{comment}{/* run the timer\_cb for the first time */}
         program \{ name: \textcolor{stringliteral}{"init2"};
            signal: \textcolor{stringliteral}{"load"};
            source: \textcolor{stringliteral}{""};
            script \{
                timer\_cb(0);
            \}
         \}
      \}
   \}
\}
\end{DoxyCodeInclude}
 