mirror of
https://github.com/co-dan/ocaml-wiringpi/
synced 2025-11-03 06:03:51 +01:00
OASIS-ify source tree
This commit is contained in:
81
test/sapin_noel.ml
Normal file
81
test/sapin_noel.ml
Normal file
@@ -0,0 +1,81 @@
|
||||
open WiringPiOcaml;;
|
||||
open ShiftReg;;
|
||||
|
||||
let g_invert = false
|
||||
and g_pulse = false
|
||||
and g_nb_reg = 2
|
||||
|
||||
(* Ici on utilise des fonctions plus souples mais moins agréables pour les tests. Pour voir les fonctions classiques, cf anim_01 *)
|
||||
let test reg leds =
|
||||
lightLeds leds;
|
||||
(* Pour montrer la différence entre les deux modes *)
|
||||
Printf.printf "The pulse mode...\n%!";
|
||||
applyRegPulse reg leds 2.;
|
||||
|
||||
Printf.printf "The classic mode...\n%!";
|
||||
applyRegAll reg leds;
|
||||
Unix.sleep 2;
|
||||
|
||||
Printf.printf "Only one led :\n%!";
|
||||
clearLeds leds;
|
||||
leds.(1) <- true;
|
||||
Printf.printf "The pulse mode...\n%!";
|
||||
applyRegPulse reg leds 2.;
|
||||
|
||||
Printf.printf "The classic mode...\n%!";
|
||||
applyRegAll reg leds;
|
||||
Unix.sleep 2
|
||||
|
||||
(* S'inspirer de ce schéma pour les animations *)
|
||||
let anim_01 reg leds n =
|
||||
for i = 0 to n do
|
||||
clearLeds leds;
|
||||
for k = 0 to (Array.length leds) - 1 do
|
||||
leds.(k) <- true;
|
||||
applyReg reg leds 0.2;
|
||||
leds.(k) <- false
|
||||
done;
|
||||
for k = (Array.length leds) - 2 downto 0 do
|
||||
leds.(k) <- true;
|
||||
applyReg reg leds 0.2;
|
||||
leds.(k) <- false
|
||||
done;
|
||||
lightLeds leds;
|
||||
applyReg reg leds 1.;
|
||||
done
|
||||
|
||||
let anim_02 reg leds n =
|
||||
let t = ref 1. in
|
||||
for i = 0 to n do
|
||||
clearLeds leds;
|
||||
for k = 0 to (Array.length leds) - 1 do
|
||||
leds.(k) <- true;
|
||||
applyReg reg leds (!t /. 10.);
|
||||
leds.(k) <- false
|
||||
done;
|
||||
for k = (Array.length leds) - 2 downto 0 do
|
||||
leds.(k) <- true;
|
||||
applyReg reg leds (!t /. 10.);
|
||||
leds.(k) <- false
|
||||
done;
|
||||
lightLeds leds;
|
||||
applyReg reg leds !t;
|
||||
t := !t /. 1.2;
|
||||
done
|
||||
|
||||
let _ =
|
||||
let t = true
|
||||
and f = false in
|
||||
(* On choisit le mode d'affichage Phys *)
|
||||
ignore(setupPhys ());
|
||||
(* reg : pin_value = p_v, pin_shift = p_s, pin_apply = p_a *)
|
||||
(* On crée le register *)
|
||||
(* En mode pulse : *)
|
||||
(* let reg = genReg 11 13 15 ~pulse:true in *)
|
||||
let reg = genReg 11 13 15 ~invert:g_invert ~pulse:g_pulse in
|
||||
(* On initialise *)
|
||||
let leds = initReg reg ~nb_reg:g_nb_reg in
|
||||
Printf.printf "Début\n%!";
|
||||
(* And a pretty animation *)
|
||||
anim_01 reg leds max_int;
|
||||
(* findLedNumber reg leds *)
|
||||
80
test/test_led.ml
Normal file
80
test/test_led.ml
Normal file
@@ -0,0 +1,80 @@
|
||||
open WiringPiOcaml;;
|
||||
open ShiftReg;;
|
||||
|
||||
let test reg leds =
|
||||
lightLeds leds;
|
||||
(* Pour montrer la différence entre les deux modes *)
|
||||
Printf.printf "The pulse mode...\n%!";
|
||||
applyRegPulse reg leds 2.;
|
||||
|
||||
Printf.printf "The classic mode...\n%!";
|
||||
applyRegAll reg leds;
|
||||
Unix.sleep 2;
|
||||
|
||||
Printf.printf "Only one led :\n%!";
|
||||
clearLeds leds;
|
||||
leds.(1) <- true;
|
||||
Printf.printf "The pulse mode...\n%!";
|
||||
applyRegPulse reg leds 2.;
|
||||
|
||||
Printf.printf "The classic mode...\n%!";
|
||||
applyRegAll reg leds;
|
||||
Unix.sleep 2
|
||||
|
||||
let _ =
|
||||
let what = Sys.argv.(1) in
|
||||
Printf.printf "%s\n" Sys.argv.(1);
|
||||
ignore(setupPhys ());
|
||||
let reg = genReg 11 13 15 ~invert:false in
|
||||
let leds = initReg reg ~nb_reg:2 in
|
||||
let t = true
|
||||
and f = false in
|
||||
clearLeds leds;
|
||||
if what = "g" then begin
|
||||
let make_t n k =
|
||||
clearLeds leds;
|
||||
for k = 0 to Array.length leds - 1 do
|
||||
if k mod 3 = 0 then
|
||||
leds.(k) <- t;
|
||||
done
|
||||
in
|
||||
make_t 3 0;
|
||||
let t1 = Array.copy leds in
|
||||
make_t 3 1;
|
||||
let t2 = Array.copy leds in
|
||||
make_t 3 2;
|
||||
let t3 = Array.copy leds in
|
||||
let t = [|t1;t2;t3|] in
|
||||
while true do
|
||||
applyReg reg t1 0.5;
|
||||
applyReg reg t2 0.5;
|
||||
applyReg reg t3 0.5;
|
||||
done
|
||||
end
|
||||
else if what = "a" then begin
|
||||
lightLeds leds;
|
||||
while true do
|
||||
applyReg reg leds 10.;
|
||||
done;
|
||||
end
|
||||
else if what = "e" then begin
|
||||
clearLeds leds;
|
||||
while true do
|
||||
applyReg reg leds 10.;
|
||||
done;
|
||||
end
|
||||
else if what = "f" then begin
|
||||
findLedNumber reg leds;
|
||||
end
|
||||
else if what = "obo" then begin
|
||||
clearLeds leds;
|
||||
leds.(int_of_string Sys.argv.(2)) <- t;
|
||||
applyReg reg leds 10.;
|
||||
end
|
||||
|
||||
|
||||
|
||||
(*
|
||||
9 -> saute la 7e (première du nvx)
|
||||
15 --> réagit légèrement
|
||||
*)
|
||||
Reference in New Issue
Block a user