-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.dats
More file actions
28 lines (25 loc) · 764 Bytes
/
main.dats
File metadata and controls
28 lines (25 loc) · 764 Bytes
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
#include "config.hats"
#include "{$TOP}/avr_prelude/kernel_staload.hats"
staload "{$TOP}/SATS/arduino.sats"
staload UN = "prelude/SATS/unsafe.sats"
#define LED 9
#define BLINK_DELAY_MS 10.0
implement main () = {
fun loop_fadein {n:nat | n <= 255} .<255 - n>. (i: int n): void = {
val () = analogWrite (LED, i)
val () = delay_ms (BLINK_DELAY_MS)
val () = if i < 255 then loop_fadein (i + 1)
}
fun loop_fadeout {n:nat | n <= 255} .<n>. (i: int n): void = {
val () = analogWrite (LED, i)
val () = delay_ms (BLINK_DELAY_MS)
val () = if i > 0 then loop_fadeout (i - 1)
}
fun forever () = {
val () = loop_fadein 0
val () = loop_fadeout 255
val () = forever ()
}
val () = pinMode (LED, OUTPUT)
val () = forever ()
}