diff --git a/_oasis b/_oasis index cfbc9ef..a6a378b 100644 --- a/_oasis +++ b/_oasis @@ -13,3 +13,8 @@ Library "WiringPi" CSources: WiringPi_stubs.c CCLib: -lwiringPi +Executable "wpi-button-example" + Path: examples/ + BuildTools: ocamlbuild + MainIs: button.ml + BuildDepends: WiringPi,unix \ No newline at end of file diff --git a/examples/button.ml b/examples/button.ml new file mode 100644 index 0000000..1170f3f --- /dev/null +++ b/examples/button.ml @@ -0,0 +1,22 @@ +open Gpio3 + +(* Set up the pins the following way: *) +(* pin 3 (pull-up) -> btn -> resistor -> gnd *) + +let setup () = + Gpio3.setup (); + pin_mode GPIO3 IN; + pull_up_dn_control GPIO3 UP + +let rec loop () = + (match digital_read GPIO3 with + | LOW -> print_endline "-- LOW" + | HIGH -> print_endline "++ HIGH"); + Unix.sleepf 0.5; + loop () + + +let _ = + setup (); + loop (); +