summaryrefslogtreecommitdiff
path: root/assignment-13/uFPL/Examples.icl
blob: 1e870e602811ebf4eb7101ee49edd230b0d0c768 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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