update
[mTask.git] / Tasks / Examples.icl
1 implementation module Tasks.Examples
2
3 import qualified Data.Map as DM
4 import mTask
5
6 import Devices.mTaskDevice
7 import iTasks._Framework.Serialization
8
9 count :: Main (ByteCode () Stmt)
10 count = sds \x=0 In {main = x =. x +. lit 1 :. pub x :. noOp}
11
12 countAndLed :: Main (ByteCode () Stmt)
13 countAndLed = sds \x=1 In sds \pinnetje=1 In {main =
14 IF (digitalRead D3) (
15 x =. x +. lit 1 :.
16 pub x
17 ) (
18 noOp
19 ) :.
20 IF (pinnetje ==. lit 1) (
21 ledOn (lit LED1)
22 ) (
23 IF (pinnetje ==. lit 2) (
24 ledOn (lit LED2)
25 ) (
26 ledOn (lit LED3)
27 )
28 )}
29
30 blinkShare :: Main (ByteCode () Stmt)
31 blinkShare = sds \x=1 In sds \led=LED1 In {main =
32 IF (x ==. lit 1) (
33 ledOn led ) (
34 ledOff led ) :.
35 x =. lit 1 -. x :. noOp
36 }
37
38 blink :: UserLED -> Main (ByteCode () Stmt)
39 blink l = sds \x=1 In {main =
40 IF (x ==. lit 1) (
41 ledOn (lit l) ) (
42 ledOff (lit l) ) :.
43 x =. lit 1 -. x :. noOp
44 }
45
46 ledtOn :: UserLED -> Main (ByteCode () Stmt)
47 ledtOn d = {main = ledOn (lit d) :. noOp}
48
49 ledtOff :: UserLED -> Main (ByteCode () Stmt)
50 ledtOff d = {main = ledOff (lit d) :. noOp}
51
52 readDPin :: DigitalPin -> Main (ByteCode () Stmt)
53 readDPin d = sds \pin=False In {main=pin =. digitalRead d :. noOp}
54
55 ledSelection :: Task UserLED
56 ledSelection = enterInformation "Select LED" []
57
58 pinSelection :: Task DigitalPin
59 pinSelection = enterInformation "Select digital pin" []
60
61 allmTasks :: Map String (Task (Main (ByteCode () Stmt)))
62 allmTasks = 'DM'.fromList
63 [("countAndLed", treturn countAndLed)
64 ,("ledOn", ledSelection @ ledtOn)
65 ,("ledOff", ledSelection @ ledtOff)
66 ,("readDPin", pinSelection @ readDPin)
67 ,("blink", ledSelection @ blink)
68 ,("blinkShare", treturn blinkShare)
69 ,("count", treturn count)
70 ]