+
+\subsubsection{Example}
+The following code shows a complete example of a \gls{Task} controlling an
+\emph{STM} microcontroller containing a heartbeat sensor. The web application
+belonging to the server shows the heartbeat value and starts an alert
+\gls{Task} when it exceeds the value given or is no longer valid.
+This example also shows how named \gls{SDS} are handled.
+
+\begin{lstlisting}[language=Clean,caption={Heartbeat example}]
+hbwatch :: (Task a) Int -> Task ()
+hbwatch alert lim
+ = makeDevice "stm32" stm32
+ >>= connectDevice
+ >>= \stm ->sendTaskToDevice "monitor" monitor (stm, OnInterval 200)
+ >>= \(t, sh)->mon (fromJust $ find (\x->x.name == "hb") sh)
+ >>* [OnAction (Action "Shutdown") $ always $ deleteDevice stm >>| shutDown 0]
+where
+ mon :: (Shared BCValue) -> Task ()
+ mon b = whileUnchanged (mapRead dynHB b)
+ \hb=:(HB i valid)->if (not valid || i > lim)
+ alert (viewInformation "HB Okay" [] hb)
+
+ dynHB :: Dynamic -> HeartBeat
+ dynHB (a :: HeartBeat) = a
+
+ monitor = namedsds \hb=(0 Named hb) In
+ {main= hb = getHB :. pub hb }
+\end{lstlisting}