Skip to content

Instantly share code, notes, and snippets.

@kashmervil
Last active August 29, 2015 14:00
Show Gist options
  • Save kashmervil/11249391 to your computer and use it in GitHub Desktop.
Save kashmervil/11249391 to your computer and use it in GitHub Desktop.
module Program
open System
open System.Collections.Generic
open System.Reactive.Linq
open Trik
let log s = printfn "%s" s
type Distance = Far | Middle | Near
let rawToDist x = match x with
| _ when x > 80 -> Near
| _ when x > 30 -> Middle
| _ -> Far
let distToSpeed x = match x with
| Near -> -100
| Middle -> 0
| Far -> 100
[<EntryPoint>]
let main _ =
log "Started"
Helpers.I2C.init "/dev/i2c-2" 0x48 1
let model = new Model()
log "Loaded"
use rightWheel = model.Motor.["JM1"]
use leftWheel = model.Motor.["JM2"]
let frontSensor = model.AnalogSensor.["JA1"].ToObservable().Select(rawToDist)
let motorActions = frontSensor.Select(distToSpeed).DistinctUntilChanged()
use r_disp = motorActions.Subscribe(rightWheel)
use l_disp = motorActions.Subscribe(leftWheel)
log "Ready (any key to finish)"
System.Console.ReadKey() |> ignore
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment