4 import gdynamic, gCons, GenEq, StdMisc, StdArray
39 ,["// --- heatingDemo \n"]
41 ,["// --- hpinDemo \n"]
49 ,["// --- lcdCount \n"]
52 ,["// --- heating \n"]
56 lcdHello = LCD 16 2 [] \lcd = {main = print lcd (lit "Hello world")}
61 If (pressed upButton) (
62 setCursor lcd Zero Zero :.
66 {main = t (sec 0) Zero}
68 printD0 = {main = serialPrint (Not d0)}
70 print36 = sds \x = 6 In {main = x =. x *. x :. serialPrint x}
73 {main = a1 =. a0 =. lit 1 +. a0 :. a0 =. Not a0}
75 fac = fun \fac = (\n. If (n <. One) One (n *. fac (n -. One)))
76 In {main = fac (lit 6)}
81 task \t = (\s. setLED s :. t (If s (sec 1) (sec 3)) (Not s)) In {main = t (sec 0) (lit True)}
83 task \t = (\(). d13 =. Not d13 :. t (sec 1) ()) In {main = t (sec 0) ()}
85 task \t = (\s. d13 =. s :. t (If s (msec 100) (sec 1)) (Not s)) In {main = t (sec 0) (lit False)}
87 task \t = (\b. d13 =. b :. t (sec 1) b) In {main = t (msec 0) true :. t (msec 100) false}
90 sec n = long (lit (n * 1000))
93 qt = task \plus = (\(x,y).x +. y) In {main = plus (sec 0) (lit 3, lit 4)}
94 qs = fun \plus = (\(x,y).x +. y) In {main = plus (lit 3, lit 4)}
97 tasks \(switch, heat) =
98 (\s1 = digitalWrite D2 s1:. heat (sec 60) s1
99 ,\s2 = analogRead A3 >>*. \v.
100 [Cond (v >. upper) (switch (sec 0) off)
101 ,Cond (v <. lower) (switch (sec 0) on)
102 ,Ever (heat (sec 1) s2)
104 In {main = heat (sec 0) off}
109 serialReadInt = serialParseInt >>=. \i. serialRead >>*. \c. [Cond (c ==. lit '\n') i]
113 fun \switch = (\s. d13 =. s) In
114 task \control = (\isOn.
115 a0 <. goal >>*. \mustOn.
116 [Cond (Not isOn &. mustOn) (switch on :. control minOnTime on)
117 ,Cond (isOn &. Not mustOn) (switch off:. control minOffTime off)
118 ,Ever (control (msec 100) isOn)
121 serialAvailable ? (serialReadInt >>=. \g.goal =. g) :.
122 change (sec 1) ()) In
123 {main = switch off :. control (sec 0) off :. change (sec 1) ()}
130 // fun \switch = setLED In
131 fun \switch = (\b. setLED b :. serialPrintln b) In
132 task \control = (\isOn.
133 a0 <. goal >>*. \mustOn.
134 [Cond (Not isOn &. mustOn) (switch on :. control minOnTime on)
135 ,Cond (isOn &. Not mustOn) (switch off:. control minOffTime off)
136 ,Ever (control (msec 100) isOn)
139 serialAvailable ? (serialReadInt >>=. \i. serialPrintln (goal =. i)) :.
140 change (sec 1) ()) In
141 {main = switch off :. control (sec 0) off :. change (sec 1) ()}
148 fun \switch = (\on. d13 =. bool on :. a0 =. on) In
150 (\isOn. a0 <. goal >>*. \mustOn.
151 [Cond (mustOn &. Not isOn) (switch mustOn :. control minOnTime mustOn)
152 ,Cond (Not mustOn &. isOn) (switch mustOn :. control minOffTime mustOn)
153 ,Ever (control (msec 100) isOn)
155 {main = switch off :. control (sec 0) off}
157 minOnTime = sec 1 // 60
158 minOffTime = sec 2 //10
165 task \tempChange = (\().
166 lit 0 <. temp &. Not heat ? temp =. temp -. One:.
167 temp <. lit 1000 &. heat ? temp =. temp +. One :.
168 setCursor lcd (lit 5) Zero :.
169 print lcd (lit "temp ") :.
171 print lcd (lit " ") :.
172 tempChange (msec 789) ()) In
175 setCursor lcd Zero Zero :.
177 (print lcd (lit "On "))
178 (print lcd (lit "Off"))) In
180 analogRead A0 >>=. \a0.
181 setCursor lcd Zero One :.
183 print lcd (lit " ") :.
185 task \control = (\isOn.
186 measure () >>=. \val.temp <. val
188 [Cond (Not isOn &. mustOn) (switch on :. control minOnTime on)
189 ,Cond (isOn &. Not mustOn) (switch off:. control minOffTime off)
190 ,Ever (control (msec 100) isOn)
193 {main = switch off :. control (msec 10) off :. tempChange (sec 0) ()}
206 setCursor lcd Zero Zero :.
208 count (sec 1) (n +. One)) In
209 {main = count (sec 0) Zero}
211 p0 :: (Main (Code Int Expr))
212 p0 = sds \x = 6 In {main = x =. x *. lit 7}
213 p1 = {main = lit 2 +. lit 4 >>=. \x. (x +. lit 1) *. x}
215 fun \f. (\x. lit 6 *. x)
216 In {main = lit 3 +. lit 4 >>=. \x. f x}
218 fun \f. (\x. lit 6 *. x)
219 In {main = lit 3 +. lit 4 >>=. f} // higher order, somewhat remarkable that this works
221 fun \f. (\x. lit 6 *. x)
222 In {main = lit 3 +. lit 4 >>=. \x. f x >>=. serialPrint}
223 p5 = {main = lit 7 >>*. \x. [Cond (x <. lit 36) (x *. x),Ever (lit 42)]}
224 p6 = sds \y = 1 In {main = lit 7 >>*. \x. [Cond (x <. lit 36) (y =. x *. x),Ever (y =. x)]}
225 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)]}
226 p8 = sds \y = 1 In {main = pressed upButton >>*. \x. [Cond x (y =. y +. y),Ever (y =. lit 36)]}
227 //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)]}
228 //p9 = {main = If (pressed upButton) (lit 1) (lit 7)} // Overloading error [mTaskTFP16.icl,61,p9]: "isExpr" no instance available of type Stmt
229 p9 = {main = pressed upButton >>=. \b.If b (lit 1) (lit 7)}
233 (pressed upButton >>*. \x.
234 [Cond x (y =. y +. y :.
236 ,Ever (y =. lit 36 :.
244 (pressed upButton >>=. \b.
251 ((y =. x *. x) >>*. \z.
252 [Cond (z ==. x) (serialPrint y)
253 ,Ever (serialPrint (lit 0))
259 task \t = (\(). pressed upButton >>*. \b.[Cond b (serialPrintln (lit 7)),Ever (t (lit 250) ():. lit 0)]) In
260 {main = t (lit 0) ()}