4 import gdynamic, gCons, GenEq, StdMisc, StdArray
37 ,["// --- heatingDemo \n"]
39 ,["// --- hpinDemo \n"]
47 ,["// --- lcdCount \n"]
50 ,["// --- heating \n"]
54 lcdHello = LCD 16 2 [] \lcd = {main = print lcd (lit "Hello world")}
59 If (pressed upButton) (
60 setCursor lcd Zero Zero :.
64 {main = t (sec 0) Zero}
66 printD0 = {main = serialPrint (Not d0)}
68 print36 = sds \x = 6 In {main = x =. x *. x :. serialPrint x}
71 {main = a1 =. a0 =. lit 1 +. a0 :. a0 =. Not a0}
73 fac = fun \fac = (\n. If (n <. One) One (n *. fac (n -. One)))
74 In {main = fac (lit 6)}
79 task \t = (\s. setLED s :. t (If s (sec 1) (sec 3)) (Not s)) In {main = t (sec 0) (lit True)}
81 task \t = (\(). d13 =. Not d13 :. t (sec 1) ()) In {main = t (sec 0) ()}
83 task \t = (\s. d13 =. s :. t (If s (msec 100) (sec 1)) (Not s)) In {main = t (sec 0) (lit False)}
85 task \t = (\b. d13 =. b :. t (sec 1) b) In {main = t (msec 0) true :. t (msec 100) false}
88 sec n = long (lit (n * 1000))
91 qt = task \plus = (\(x,y).x +. y) In {main = plus (sec 0) (lit 3, lit 4)}
92 qs = fun \plus = (\(x,y).x +. y) In {main = plus (lit 3, lit 4)}
95 tasks \(switch, heat) =
96 (\s1 = digitalWrite D2 s1:. heat (sec 60) s1
97 ,\s2 = analogRead A3 >>*. \v.
98 [Cond (v >. upper) (switch (sec 0) off)
99 ,Cond (v <. lower) (switch (sec 0) on)
100 ,Ever (heat (sec 1) s2)
102 In {main = heat (sec 0) off}
107 serialReadInt = serialParseInt >>=. \i. serialRead >>*. \c. [Cond (c ==. lit '\n') i]
111 fun \switch = (\s. d13 =. s) In
112 task \control = (\isOn.
113 a0 <. goal >>*. \mustOn.
114 [Cond (Not isOn &. mustOn) (switch on :. control minOnTime on)
115 ,Cond (isOn &. Not mustOn) (switch off:. control minOffTime off)
116 ,Ever (control (msec 100) isOn)
119 serialAvailable ? (serialReadInt >>=. \g.goal =. g) :.
120 change (sec 1) ()) In
121 {main = switch off :. control (sec 0) off :. change (sec 1) ()}
128 // fun \switch = setLED In
129 fun \switch = (\b. setLED b :. serialPrintln b) In
130 task \control = (\isOn.
131 a0 <. goal >>*. \mustOn.
132 [Cond (Not isOn &. mustOn) (switch on :. control minOnTime on)
133 ,Cond (isOn &. Not mustOn) (switch off:. control minOffTime off)
134 ,Ever (control (msec 100) isOn)
137 serialAvailable ? (serialReadInt >>=. \i. serialPrintln (goal =. i)) :.
138 change (sec 1) ()) In
139 {main = switch off :. control (sec 0) off :. change (sec 1) ()}
146 fun \switch = (\on. d13 =. bool on :. a0 =. on) In
148 (\isOn. a0 <. goal >>*. \mustOn.
149 [Cond (mustOn &. Not isOn) (switch mustOn :. control minOnTime mustOn)
150 ,Cond (Not mustOn &. isOn) (switch mustOn :. control minOffTime mustOn)
151 ,Ever (control (msec 100) isOn)
153 {main = switch off :. control (sec 0) off}
155 minOnTime = sec 1 // 60
156 minOffTime = sec 2 //10
163 task \tempChange = (\().
164 lit 0 <. temp &. Not heat ? temp =. temp -. One:.
165 temp <. lit 1000 &. heat ? temp =. temp +. One :.
166 setCursor lcd (lit 5) Zero :.
167 print lcd (lit "temp ") :.
169 print lcd (lit " ") :.
170 tempChange (msec 789) ()) In
173 setCursor lcd Zero Zero :.
175 (print lcd (lit "On "))
176 (print lcd (lit "Off"))) In
178 analogRead A0 >>=. \a0.
179 setCursor lcd Zero One :.
181 print lcd (lit " ") :.
183 task \control = (\isOn.
184 measure () >>=. \val.temp <. val
186 [Cond (Not isOn &. mustOn) (switch on :. control minOnTime on)
187 ,Cond (isOn &. Not mustOn) (switch off:. control minOffTime off)
188 ,Ever (control (msec 100) isOn)
191 {main = switch off :. control (msec 10) off :. tempChange (sec 0) ()}
204 setCursor lcd Zero Zero :.
206 count (sec 1) (n +. One)) In
207 {main = count (sec 0) Zero}
209 p0 = sds \x = 6 In {main = x =. x *. lit 7}
210 p1 = {main = lit 2 +. lit 4 >>=. \x. (x +. lit 1) *. x}
212 fun \f. (\x. lit 6 *. x)
213 In {main = lit 3 +. lit 4 >>=. \x. f x}
215 fun \f. (\x. lit 6 *. x)
216 In {main = lit 3 +. lit 4 >>=. f} // higher order, somewhat remarkable that this works
218 fun \f. (\x. lit 6 *. x)
219 In {main = lit 3 +. lit 4 >>=. \x. f x >>=. serialPrint}
220 p5 = {main = lit 7 >>*. \x. [Cond (x <. lit 36) (x *. x),Ever (lit 42)]}
221 p6 = sds \y = 1 In {main = lit 7 >>*. \x. [Cond (x <. lit 36) (y =. x *. x),Ever (y =. x)]}
222 p7 = sds \y = 1 In {main = y +. lit 1 >>*. \x. [Cond (x <. lit 36) ((y =. x *. x) >>*. \z.[Cond (z ==. x) y, Ever y]),Ever (y =. x)]}
223 p8 = sds \y = 1 In {main = pressed upButton >>*. \x. [Cond x (y =. y +. y),Ever (y =. lit 36)]}
224 //p8 = sds \y = 1 In {main = pressed upButton >>*. \x. [Cond x ((y =. lit 42) >>*. \z.[Cond (z ==. y) y, Ever y]),Ever (y =. lit 36)]}
225 //p9 = {main = If (pressed upButton) (lit 1) (lit 7)} // Overloading error [mTaskTFP16.icl,61,p9]: "isExpr" no instance available of type Stmt
226 p9 = {main = pressed upButton >>=. \b.If b (lit 1) (lit 7)}
230 (pressed upButton >>*. \x.
231 [Cond x (y =. y +. y :.
233 ,Ever (y =. lit 36 :.
241 (pressed upButton >>=. \b.
248 ((y =. x *. x) >>*. \z.
249 [Cond (z ==. x) (serialPrint y)
250 ,Ever (serialPrint (lit 0))
256 task \t = (\(). pressed upButton >>*. \b.[Cond b (serialPrintln (lit 7)),Ever (t (lit 250) ():. lit 0)]) In
257 {main = t (lit 0) ()}