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


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

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

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