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


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{collections \{}
\DoxyCodeLine{   group \{ name: "{}main"{};}
\DoxyCodeLine{      script \{}
\DoxyCodeLine{         public timer\_cb(val) \{}
\DoxyCodeLine{            new x, y, w, h;}
\DoxyCodeLine{            new buf[32];}
\DoxyCodeLine{}
\DoxyCodeLine{            /* set labels with object info */}
\DoxyCodeLine{            get\_geometry(PART:"{}red\_rect"{}, x, y, w, h);}
\DoxyCodeLine{            snprintf(buf, sizeof(buf), "{}Timer called \%d times."{}, val);}
\DoxyCodeLine{            set\_text(PART:"{}label1"{}, buf)}
\DoxyCodeLine{            snprintf(buf, sizeof(buf), "{}Object x: \%d  w: \%d"{}, x, w);}
\DoxyCodeLine{            set\_text(PART:"{}label2"{}, buf)}
\DoxyCodeLine{}
\DoxyCodeLine{            /* renew the timer */}
\DoxyCodeLine{            timer(1 / 30, "{}timer\_cb"{}, val + 1);}
\DoxyCodeLine{         \}}
\DoxyCodeLine{      \}}
\DoxyCodeLine{      parts \{}
\DoxyCodeLine{         part \{ name: "{}bg"{};}
\DoxyCodeLine{            type: RECT;}
\DoxyCodeLine{            description \{ state: "{}default"{} 0.0;}
\DoxyCodeLine{               color: 255 255 255 255;}
\DoxyCodeLine{            \}}
\DoxyCodeLine{         \}}
\DoxyCodeLine{         part \{ name: "{}label1"{};}
\DoxyCodeLine{            type: TEXT;}
\DoxyCodeLine{            description \{ state: "{}default"{} 0.0;}
\DoxyCodeLine{               color: 0 0 0 255;}
\DoxyCodeLine{               text \{}
\DoxyCodeLine{                  text: "{}"{};}
\DoxyCodeLine{                  font: "{}Sans"{};}
\DoxyCodeLine{                  size: 12;}
\DoxyCodeLine{                  align: 0.0 0.7;}
\DoxyCodeLine{               \}}
\DoxyCodeLine{            \}}
\DoxyCodeLine{         \}}
\DoxyCodeLine{         part \{ name: "{}label2"{};}
\DoxyCodeLine{            type: TEXT;}
\DoxyCodeLine{            description \{ state: "{}default"{} 0.0;}
\DoxyCodeLine{               color: 0 0 0 255;}
\DoxyCodeLine{               text \{}
\DoxyCodeLine{                  font: "{}Sans"{};}
\DoxyCodeLine{                  size: 12;}
\DoxyCodeLine{                  align: 0.0 0.8;}
\DoxyCodeLine{               \}}
\DoxyCodeLine{            \}}
\DoxyCodeLine{         \}}
\DoxyCodeLine{         part \{ name: "{}red\_rect"{};}
\DoxyCodeLine{            type: RECT;}
\DoxyCodeLine{            description \{ state: "{}default"{} 0.0;}
\DoxyCodeLine{               color: 255 0 0 255;}
\DoxyCodeLine{               max: 30 30;}
\DoxyCodeLine{               align: 0.1 0.2;}
\DoxyCodeLine{            \}}
\DoxyCodeLine{            description \{ state: "{}default"{} 1.0;}
\DoxyCodeLine{               inherit: "{}default"{} 0.0;}
\DoxyCodeLine{               color: 0 0 255 255;}
\DoxyCodeLine{               max: 50 30;}
\DoxyCodeLine{               align: 0.9 0.2;}
\DoxyCodeLine{            \}}
\DoxyCodeLine{         \}}
\DoxyCodeLine{      \}}
\DoxyCodeLine{      programs \{}
\DoxyCodeLine{         /* move the red rect back an forth in a loop */}
\DoxyCodeLine{         program \{ name: "{}init"{};}
\DoxyCodeLine{            signal: "{}load"{};}
\DoxyCodeLine{            source: "{}"{};}
\DoxyCodeLine{            action: STATE\_SET "{}default"{} 1.0;}
\DoxyCodeLine{            transition: SINUSOIDAL 1.0;}
\DoxyCodeLine{            target: "{}red\_rect"{};}
\DoxyCodeLine{            after: "{}loop"{};}
\DoxyCodeLine{         \}}
\DoxyCodeLine{         program \{ name: "{}loop"{};}
\DoxyCodeLine{            action: STATE\_SET "{}default"{} 0.0;}
\DoxyCodeLine{            transition: SINUSOIDAL 1.0;}
\DoxyCodeLine{            target: "{}red\_rect"{};}
\DoxyCodeLine{            after: "{}init"{};}
\DoxyCodeLine{         \}}
\DoxyCodeLine{         /* run the timer\_cb for the first time */}
\DoxyCodeLine{         program \{ name: "{}init2"{};}
\DoxyCodeLine{            signal: "{}load"{};}
\DoxyCodeLine{            source: "{}"{};}
\DoxyCodeLine{            script \{}
\DoxyCodeLine{                timer\_cb(0);}
\DoxyCodeLine{            \}}
\DoxyCodeLine{         \}}
\DoxyCodeLine{      \}}
\DoxyCodeLine{   \}}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 