say something about shields
[msc-thesis1617.git] / mtask.examples.tex
1 Some example \gls{mTask}-\glspl{Task} using almost all of their functionality
2 are shown in Listing~\ref{lst:exmtask}. The \gls{mTask}-\glspl{Task} shown in
3 the example do not belong to a particular view and therefore are of the type
4 \CI{View t r}. The \CI{blink} \gls{mTask} show the classic \gls{Arduino}
5 blinking led application that blinks a certain \gls{LED} every second. The
6 \CI{thermostat} expression will enable a digital pin powering a cooling fan
7 when the analog pin representing a temperature sensor is too high.
8 \CI{thermostat`} shows the same expression but now using the assignment style
9 \gls{GPIO} technique. The \CI{thermostat} example also shows that it is not
10 necessary to run everything as a \CI{task}. The main program code can also just
11 consist of the contents of the root \CI{main} itself.
12
13 \begin{lstlisting}[%
14 label={lst:exmtask},caption={Some example \gls{mTask}-\glspl{Task}}]
15 blink = task \blink=(\x.
16 IF (x ==. lit True) (ledOn led) (ledOff led) :.
17 blink (lit 1000) (Not x)
18 In {main=blink (lit 1000) True}
19
20 thermostat :: Main (View () Stmt)
21 thermostat = {main =
22 IF (analogRead A0 >. lit 50)
23 ( digitalWrite D0 (lit True) )
24 ( digitalWrite D0 (lit False) )
25 }
26
27 thermostat` :: Main (View () Stmt)
28 thermostat` = let
29 a0 = aIO A0
30 d0 = dIO D0 in {main = IF (a0 >. lit 50) (d0 =. lit True) (d0 =. lit False) }
31 \end{lstlisting}