module mTaskExamples import iTasks import GenEq, StdMisc, StdArray import mTask Start = [["//mTaskTFP16_3 \n"] ,["// --- p0 \n"] ,compile p0 ,["// --- p1 \n"] ,compile p1 ,["// --- p2 \n"] ,compile p2 ,["// --- p3 \n"] ,compile p3 ,["// --- p4 \n"] ,compile p4 ,["// --- p5 \n"] ,compile p5 ,["// --- p6 \n"] ,compile p6 ,["// --- p7 \n"] ,compile p7 ,["// --- p8 \n"] ,compile p8 ,["// --- p9 \n"] ,compile p9 ,["// --- p10 \n"] ,compile p10 ,["// --- p11 \n"] ,compile p11 ,["// --- p12 \n"] ,compile p12 ,["// --- fac \n"] ,compile fac ,["// --- blink \n"] ,compile blink ,["// --- heatingDemo \n"] ,compile heatingDemo ,["// --- hpinDemo \n"] ,compile pinDemo ,["// --- blink2 \n"] ,compile blink2 ,["// --- blink3 \n"] ,compile blink3 ,["// --- blinks \n"] ,compile blinks ,["// --- lcdCount \n"] ,compile lcdCount ,["// --- heating \n"] ,compile heating ] lcdHello = LCD 16 2 [] \lcd = {main = print lcd (lit "Hello world")} lcdCount = LCD 16 2 [] \lcd = task \t = (\c. If (pressed upButton) ( setCursor lcd Zero Zero :. print lcd c :. t (sec 1) (c +. One) ) (t (msec 10) c)) In {main = t (sec 0) Zero} printD0 = {main = serialPrint (Not d0)} print36 = sds \x = 6 In {main = x =. x *. x :. serialPrint x} pinDemo = {main = a1 =. a0 =. lit 1 +. a0 :. a0 =. Not a0} fac = fun \fac = (\n. If (n <. One) One (n *. fac (n -. One))) In {main = fac (lit 6)} One = lit 1 Zero = lit 0 blink = task \t = (\s. setLED s :. t (If s (sec 1) (sec 3)) (Not s)) In {main = t (sec 0) (lit True)} blink2 = task \t = (\(). d13 =. Not d13 :. t (sec 1) ()) In {main = t (sec 0) ()} blink3 = task \t = (\s. d13 =. s :. t (If s (msec 100) (sec 1)) (Not s)) In {main = t (sec 0) (lit False)} blinks = task \t = (\b. d13 =. b :. t (sec 1) b) In {main = t (msec 0) true :. t (msec 100) false} setLED b = d13 =. b sec n = long (lit (n * 1000)) msec n = long (lit n) qt = task \plus = (\(x,y).x +. y) In {main = plus (sec 0) (lit 3, lit 4)} qs = fun \plus = (\(x,y).x +. y) In {main = plus (lit 3, lit 4)} q1 = tasks \(switch, heat) = (\s1 = digitalWrite D2 s1:. heat (sec 60) s1 ,\s2 = analogRead A3 >>*. \v. [Cond (v >. upper) (switch (sec 0) off) ,Cond (v <. lower) (switch (sec 0) on) ,Ever (heat (sec 1) s2) ]) In {main = heat (sec 0) off} where upper = lit 876 lower = lit 123 serialReadInt = serialParseInt >>=. \i. serialRead >>*. \c. [Cond (c ==. lit '\n') i] heating = sds \goal = 500 In fun \switch = (\s. d13 =. s) In task \control = (\isOn. a0 <. goal >>*. \mustOn. [Cond (Not isOn &. mustOn) (switch on :. control minOnTime on) ,Cond (isOn &. Not mustOn) (switch off:. control minOffTime off) ,Ever (control (msec 100) isOn) ]) In task \change = (\(). serialAvailable ? (serialReadInt >>=. \g.goal =. g) :. change (sec 1) ()) In {main = switch off :. control (sec 0) off :. change (sec 1) ()} where minOnTime = sec 2 minOffTime = sec 1 heating2 = sds \goal = 500 In // fun \switch = setLED In fun \switch = (\b. setLED b :. serialPrintln b) In task \control = (\isOn. a0 <. goal >>*. \mustOn. [Cond (Not isOn &. mustOn) (switch on :. control minOnTime on) ,Cond (isOn &. Not mustOn) (switch off:. control minOffTime off) ,Ever (control (msec 100) isOn) ]) In task \change = (\(). serialAvailable ? (serialReadInt >>=. \i. serialPrintln (goal =. i)) :. change (sec 1) ()) In {main = switch off :. control (sec 0) off :. change (sec 1) ()} where minOnTime = sec 2 minOffTime = sec 1 thermoTask = sds \goal = 500 In fun \switch = (\on. d13 =. bool on :. a0 =. on) In task \control = (\isOn. a0 <. goal >>*. \mustOn. [Cond (mustOn &. Not isOn) (switch mustOn :. control minOnTime mustOn) ,Cond (Not mustOn &. isOn) (switch mustOn :. control minOffTime mustOn) ,Ever (control (msec 100) isOn) ]) In {main = switch off :. control (sec 0) off} where minOnTime = sec 1 // 60 minOffTime = sec 2 //10 off = lit False heatingDemo = sds \heat = False In sds \temp = 500 In LCD 16 2 [] \lcd. task \tempChange = (\(). lit 0 <. temp &. Not heat ? temp =. temp -. One:. temp <. lit 1000 &. heat ? temp =. temp +. One :. setCursor lcd (lit 5) Zero :. print lcd (lit "temp ") :. print lcd temp :. print lcd (lit " ") :. tempChange (msec 789) ()) In fun \switch = (\s. heat =. s :. setCursor lcd Zero Zero :. If s (print lcd (lit "On ")) (print lcd (lit "Off"))) In fun \measure = (\(). analogRead A0 >>=. \a0. setCursor lcd Zero One :. print lcd a0 :. print lcd (lit " ") :. a0) In task \control = (\isOn. measure () >>=. \val.temp <. val >>*. \mustOn. [Cond (Not isOn &. mustOn) (switch on :. control minOnTime on) ,Cond (isOn &. Not mustOn) (switch off:. control minOffTime off) ,Ever (control (msec 100) isOn) ] ) In {main = switch off :. control (msec 10) off :. tempChange (sec 0) ()} where limit = lit 512 minOnTime = sec 3 minOffTime = sec 2 true = lit True on = true false = lit False off = false count = LCD 16 2 [] \lcd. task \count = (\n. setCursor lcd Zero Zero :. print lcd n :. count (sec 1) (n +. One)) In {main = count (sec 0) Zero} p0 :: (Main (Code Int Expr)) p0 = sds \x = 6 In {main = x =. x *. lit 7} p1 = {main = lit 2 +. lit 4 >>=. \x. (x +. lit 1) *. x} p2 = fun \f. (\x. lit 6 *. x) In {main = lit 3 +. lit 4 >>=. \x. f x} p3 = fun \f. (\x. lit 6 *. x) In {main = lit 3 +. lit 4 >>=. f} // higher order, somewhat remarkable that this works p4 = fun \f. (\x. lit 6 *. x) In {main = lit 3 +. lit 4 >>=. \x. f x >>=. serialPrint} p5 = {main = lit 7 >>*. \x. [Cond (x <. lit 36) (x *. x),Ever (lit 42)]} p6 = sds \y = 1 In {main = lit 7 >>*. \x. [Cond (x <. lit 36) (y =. x *. x),Ever (y =. x)]} 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)]} p8 = sds \y = 1 In {main = pressed upButton >>*. \x. [Cond x (y =. y +. y),Ever (y =. lit 36)]} //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)]} //p9 = {main = If (pressed upButton) (lit 1) (lit 7)} // Overloading error [mTaskTFP16.icl,61,p9]: "isExpr" no instance available of type Stmt p9 = {main = pressed upButton >>=. \b.If b (lit 1) (lit 7)} p10 = sds \y = 1 In {main = (pressed upButton >>*. \x. [Cond x (y =. y +. y :. x) ,Ever (y =. lit 36 :. lit False) ]) >>=. \z. z &. z} p11 = sds \y = 1 In {main = y =. lit 2 :. (pressed upButton >>=. \b. If b (y =. lit 3 :. y +. lit 1) (lit 42)) >>*. \x. [Cond (x <. lit 36) ((y =. x *. x) >>*. \z. [Cond (z ==. x) (serialPrint y) ,Ever (serialPrint (lit 0)) ]) ,Ever (y =. x) ] } p12 = task \t = (\(). pressed upButton >>*. \b.[Cond b (serialPrintln (lit 7)),Ever (t (lit 250) ():. lit 0)]) In {main = t (lit 0) ()}