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