mirror of
https://github.com/co-dan/ocaml-wiringpi/
synced 2025-11-03 06:03:51 +01:00
add an example
This commit is contained in:
22
examples/button.ml
Normal file
22
examples/button.ml
Normal 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 ();
|
||||
|
||||
Reference in New Issue
Block a user