add an example

This commit is contained in:
dan 2019-02-09 23:43:08 +01:00
parent 5b9eb6b429
commit 0beb92d299
2 changed files with 27 additions and 0 deletions

5
_oasis
View File

@ -13,3 +13,8 @@ Library "WiringPi"
CSources: WiringPi_stubs.c CSources: WiringPi_stubs.c
CCLib: -lwiringPi CCLib: -lwiringPi
Executable "wpi-button-example"
Path: examples/
BuildTools: ocamlbuild
MainIs: button.ml
BuildDepends: WiringPi,unix

22
examples/button.ml Normal file
View File

@ -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 ();