-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathProgram.fs
56 lines (49 loc) · 1.62 KB
/
Program.fs
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
open System
open System.Threading
type Color = Black | Red | Green | Blue | Cyan | Magenta | Yellow | White
let toConsoleColor = function
| Black -> ConsoleColor.Black
| Red -> ConsoleColor.Red
| Green -> ConsoleColor.Green
| Blue -> ConsoleColor.Blue
| Cyan -> ConsoleColor.Cyan
| Magenta -> ConsoleColor.Magenta
| Yellow -> ConsoleColor.Yellow
| White -> ConsoleColor.White
let toColor = function
| 'K' -> Black
| 'R' -> Red
| 'G' -> Green
| 'B' -> Blue
| 'C' -> Cyan
| 'M' -> Magenta
| 'Y' -> Yellow
| 'W' -> White
| c -> sprintf "Unknown color code: %c" c |> failwith
let toColors = Seq.map toColor
let show color =
Console.BackgroundColor <- toConsoleColor color
Console.Clear()
let flash colors =
colors |> Seq.iter (fun c -> show c; Thread.Sleep 50)
show White
let savedBG = Console.BackgroundColor
let savedFG = Console.ForegroundColor
show White
Console.ForegroundColor <- toConsoleColor Black
printfn "Place OzoBot on the screen and press"
let args = Environment.GetCommandLineArgs ()
if args.Length > 1 then
let prog = args.[1]
printfn "Press [ENTER] to program:\n%s" prog
Console.ReadLine() |> ignore
prog |> toColors |> flash
show White
printfn "Done. Press [ENTER]"
Console.ReadLine() |> ignore
else // no program
printfn "No program given. Hold Ozobot's power button for 2 seconds and place against white background to calibrate."
Console.ReadLine() |> ignore
Console.BackgroundColor <- savedBG
Console.ForegroundColor <- savedFG
Console.Clear()