mirror of
				https://github.com/co-dan/ocaml-wiringpi/
				synced 2025-10-31 04:53:51 +01:00 
			
		
		
		
	add an example
This commit is contained in:
		
							
								
								
									
										5
									
								
								_oasis
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								_oasis
									
									
									
									
									
								
							| @@ -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
									
								
							
							
						
						
									
										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