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


\begin{DoxyCodeInclude}
1 collections \{
2    group \{ name: "main";
3       script \{
4          public timer\_cb(val) \{
5             new x, y, w, h;
6             new buf[32];
7 
8             /* set labels with object info */
9             get\_geometry(PART:"red\_rect", x, y, w, h);
10             snprintf(buf, sizeof(buf), "Timer called %d times.", val);
11             set\_text(PART:"label1", buf)
12             snprintf(buf, sizeof(buf), "Object x: %d  w: %d", x, w);
13             set\_text(PART:"label2", buf)
14 
15             /* renew the timer */
16             timer(1 / 30, "timer\_cb", val + 1);
17          \}
18       \}
19       parts \{
20          part \{ name: "bg";
21             type: RECT;
22             description \{ state: "default" 0.0;
23                color: 255 255 255 255;
24             \}
25          \}
26          part \{ name: "label1";
27             type: TEXT;
28             description \{ state: "default" 0.0;
29                color: 0 0 0 255;
30                text \{
31                   text: "";
32                   font: "Sans";
33                   size: 12;
34                   align: 0.0 0.7;
35                \}
36             \}
37          \}
38          part \{ name: "label2";
39             type: TEXT;
40             description \{ state: "default" 0.0;
41                color: 0 0 0 255;
42                text \{
43                   font: "Sans";
44                   size: 12;
45                   align: 0.0 0.8;
46                \}
47             \}
48          \}
49          part \{ name: "red\_rect";
50             type: RECT;
51             description \{ state: "default" 0.0;
52                color: 255 0 0 255;
53                max: 30 30;
54                align: 0.1 0.2;
55             \}
56             description \{ state: "default" 1.0;
57                inherit: "default" 0.0;
58                color: 0 0 255 255;
59                max: 50 30;
60                align: 0.9 0.2;
61             \}
62          \}
63       \}
64       programs \{
65          /* move the red rect back an forth in a loop */
66          program \{ name: "init";
67             signal: "load";
68             source: "";
69             action: STATE\_SET "default" 1.0;
70             transition: SINUSOIDAL 1.0;
71             target: "red\_rect";
72             after: "loop";
73          \}
74          program \{ name: "loop";
75             action: STATE\_SET "default" 0.0;
76             transition: SINUSOIDAL 1.0;
77             target: "red\_rect";
78             after: "init";
79          \}
80          /* run the timer\_cb for the first time */
81          program \{ name: "init2";
82             signal: "load";
83             source: "";
84             script \{
85                 timer\_cb(0);
86             \}
87          \}
88       \}
89    \}
90 \}
\end{DoxyCodeInclude}
 