summaryrefslogtreecommitdiff
path: root/assignment-13/uFPL/Examples.icl
diff options
context:
space:
mode:
authorCamil Staps2018-01-07 17:12:34 +0100
committerCamil Staps2018-01-07 17:12:34 +0100
commit8578faf533ef5ed200b722ebc8551f32ace3a5cf (patch)
treee149a38e0ac89666b41b72f3e5b9f02374867fab /assignment-13/uFPL/Examples.icl
parentIgnore .ino (diff)
Cleanup code
Diffstat (limited to 'assignment-13/uFPL/Examples.icl')
-rw-r--r--assignment-13/uFPL/Examples.icl70
1 files changed, 70 insertions, 0 deletions
diff --git a/assignment-13/uFPL/Examples.icl b/assignment-13/uFPL/Examples.icl
new file mode 100644
index 0000000..1e870e6
--- /dev/null
+++ b/assignment-13/uFPL/Examples.icl
@@ -0,0 +1,70 @@
+implementation module uFPL.Examples
+
+import StdChar
+import StdInt
+import StdString
+
+import uFPL
+import uFPL.Bootstrap
+
+example_empty :: (String, [NamedRule])
+example_empty = ("my_program", [])
+
+example_score :: (String, [NamedRule])
+example_score = ("score",
+ "a" :=: pressed b0 >>> [scorea <# scorea +. lit 1]
+ ||| "b" :=: pressed b1 >>> [scoreb <# scoreb +. lit 1]
+ ||| "r" :=: pressed b2 >>> (
+ scorea <# lit 0 :.
+ scoreb <# lit 0 :.
+ SetCursor (lit 0, lit 0) :. // Reset screen
+ PrintS " "
+ )
+ ||| "print" :=: (Change scorea ?| Change scoreb) >>> (
+ SetCursor (lit 0, lit 0) :.
+ PrintS "A: " :.
+ Print scorea :.
+ PrintS " - B: " :.
+ Print scoreb
+ ))
+where
+ scorea = rwInt "scorea" 0
+ scoreb = rwInt "scoreb" 0
+
+example_countdown :: (String, [NamedRule])
+example_countdown = ("countdown",
+ "time" :=:
+ (Change millis >>> [When (millis -. DELAY >. counter) (
+ counter <# counter +. DELAY :.
+ seconds <# running ? (seconds -. lit 1, seconds)
+ )]) :.
+ seconds ?= lit -1 >>> (
+ minutes <# minutes -. lit 1 :.
+ seconds <# lit 59
+ ) :.
+ minutes ?= lit -1 >>> (
+ running <# false :.
+ minutes <# lit 0 :.
+ seconds <# lit 0
+ ) :.
+ Change seconds >>> (
+ SetCursor (lit 0, lit 0) :.
+ When (minutes <. lit 10) [Print (lit 0)] :.
+ Print minutes :.
+ Print (lit ':') :.
+ When (seconds <. lit 10) [Print (lit 0)] :.
+ Print seconds
+ )
+ ||| "setsec" :=: pressed b0 >>> [seconds <# seconds +. lit 1]
+ ||| "setmin" :=: pressed b1 >>> [minutes <# minutes +. lit 1]
+ ||| "on_off" :=: pressed b2 >>> [running <# running ? (false, true)]
+ ||| "reset" :=: pressed b3 >>> (
+ seconds <# lit 0 :.
+ minutes <# lit 0
+ ))
+where
+ running = rwBool "running" False
+ minutes = rwInt "minutes" 0
+ seconds = rwInt "seconds" 15
+ counter = rwULong "counter" 0 // If set to 0, this will overflow on first iteration
+ DELAY = lit 1000