78b0d678eb7d45557333e1e6741acca1ecf8ceec
[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 countTo5 :: Main (ByteCode () Stmt)
10 countTo5 = sds \x=0 In {main =
11 x =. x +. lit 1 :.
12 pub x :.
13 IF ( x >. lit 5) (
14 retrn x
15 ) (
16 noOp
17 )}
18
19 count :: Main (ByteCode () Stmt)
20 count = sds \x=0 In {main = x =. x +. lit 1 :. pub x :. noOp}
21
22 countAndLed :: Main (ByteCode () Stmt)
23 countAndLed = sds \x=1 In sds \pinnetje=1 In {main =
24 IF (digitalRead D3) (
25 x =. x +. lit 1 :.
26 pub x
27 ) (
28 noOp
29 ) :.
30 IF (pinnetje ==. lit 1) (
31 ledOn (lit LED1)
32 ) (
33 IF (pinnetje ==. lit 2) (
34 ledOn (lit LED2)
35 ) (
36 ledOn (lit LED3)
37 )
38 )}
39
40 blinkShare :: Main (ByteCode () Stmt)
41 blinkShare = sds \x=1 In sds \led=LED1 In {main =
42 IF (x ==. lit 1) (
43 ledOn led ) (
44 ledOff led ) :.
45 x =. lit 1 -. x :. noOp
46 }
47
48 blink :: UserLED -> Main (ByteCode () Stmt)
49 blink l = sds \x=1 In {main =
50 IF (x ==. lit 1) (
51 ledOn (lit l) ) (
52 ledOff (lit l) ) :.
53 x =. lit 1 -. x :. noOp
54 }
55
56 ledtOn :: UserLED -> Main (ByteCode () Stmt)
57 ledtOn d = {main = ledOn (lit d) :. noOp}
58
59 ledtOff :: UserLED -> Main (ByteCode () Stmt)
60 ledtOff d = {main = ledOff (lit d) :. noOp}
61
62 readDPin :: DigitalPin -> Main (ByteCode () Stmt)
63 readDPin d = sds \pin=False In {main=pin =. digitalRead d :. pub pin :. noOp}
64
65 ledSelection :: Task UserLED
66 ledSelection = enterInformation "Select LED" []
67
68 pinSelection :: Task DigitalPin
69 pinSelection = enterInformation "Select digital pin" []
70
71 allmTasks :: Map String (Task (Main (ByteCode () Stmt)))
72 allmTasks = 'DM'.fromList
73 [("countAndLed", treturn countAndLed)
74 ,("ledOn", ledSelection @ ledtOn)
75 ,("ledOff", ledSelection @ ledtOff)
76 ,("readDPin", pinSelection @ readDPin)
77 ,("blink", ledSelection @ blink)
78 ,("blinkShare", treturn blinkShare)
79 ,("count", treturn count)
80 ,("countTo5", treturn countTo5)
81 ]