X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=mtask.examples.tex;h=9369eece4c0f919241ce2115a90655ca355d597c;hb=9b3d5ac89173801dffb60470b86a61390c4ab68d;hp=db15f5f3758f396597a7e1162d7465a2a5f98b70;hpb=d66b8c6bae6fde77e7ba53759f862364a9505ace;p=msc-thesis1617.git diff --git a/mtask.examples.tex b/mtask.examples.tex index db15f5f..9369eec 100644 --- a/mtask.examples.tex +++ b/mtask.examples.tex @@ -1,32 +1,32 @@ Some example \gls{mTask}-\glspl{Task} --- using almost all of their -functionality --- are shown in Listing~\ref{lst:exmtask}. The -\gls{mTask}-\glspl{Task} shown in the example do not belong to a particular -view and therefore are of the type \CI{View t r}. The \CI{blink} \gls{mTask} -show the classic \gls{Arduino} blinking led application that blinks a certain -\gls{LED} every second. The \CI{thermostat} expression will enable a digital -pin powering a cooling fan when the analog pin representing a temperature -sensor is too high. \CI{thermostat`} shows the same expression but now using -the assignment style \gls{GPIO} technique. The \CI{thermostat} example also -shows that it is not necessary to run everything as a \CI{task}. The main -program code can also just consist of the contents of the root \CI{main} -itself. +functionality --- are shown in Listing~\ref{lst:exmtask}. The \CI{blink} +\gls{mTask} show the classic \gls{Arduino} blinking \gls{LED} application that +blinks a certain \gls{LED} every second. The \CI{thermostat} expression will +enable a digital pin powering a cooling fan when the analog pin representing a +temperature sensor is too high. \CI{thermostat`} shows the same expression but +now using the assignment style \gls{GPIO} technique. The \CI{thermostat} +example also shows that it is not necessary to run everything as a \CI{task}. +The main program code can also just consist of the contents of the root +\CI{main} itself. Finally a thermostat example is shown that also displays the +temperature on its \gls{LCD} while regulating the temperature. \begin{lstlisting}[% label={lst:exmtask},caption={Some example \gls{mTask}-\glspl{Task}}] -blink = task \blink=(\x. +a0 = aIO A0 +d0 = dIO D0 + +blink = task \blink.(\x. IF (x ==. lit True) (ledOn led) (ledOff led) :. blink (lit 1000) (Not x) In {main=blink (lit 1000) True} -thermostat :: Main (View () Stmt) -thermostat = {main = - IF (analogRead A0 >. lit 50) - ( digitalWrite D0 (lit True) ) - ( digitalWrite D0 (lit False) ) - } +thermostat = {main = digitalWrite D0 (analogRead A0 >. lit 50) } + +thermostat` = {main = d0 =. a0 > lit 50 } -thermostat` :: Main (View () Stmt) -thermostat` = let - a0 = aIO A0 - d0 = dIO D0 in {main = IF (a0 >. lit 50) (d0 =. lit True) (d0 =. lit False) } +thermostat`` = task \th.(\lcd. + d0 =. a0 > lit 50 :. + print lcd a0 :. + th (lit 1000) lim ) In + LCD 16 12 [] \lcd.{main = th (lit 1000) lim } \end{lstlisting}