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