hier der source unseres moduls click ausder oscat lib das verschiedenste clicks auswertet, auch doppelclick
FUNCTION_BLOCK click
VAR_INPUT
in : BOOL;
END_VAR
VAR_OUTPUT
Q : BOOL;
single : BOOL;
double : BOOL;
triple : BOOL;
status: BYTE;
END_VAR
VAR_INPUT CONSTANT
T_debounce : TIME := t#10ms;
T_short : TIME := t#200ms;
T_pause : TIME := t#500ms;
T_reconfig : TIME := t#1m;
END_VAR
VAR
debounce : TON;
tx : TIME;
last : TIME;
init : BOOL;
edge : BOOL;
standby: BOOL;
state: INT;
END_VAR
(*
version 1.0 15 Feb 2006
programmer oscat
tested by tobias
*)
(* read system time *)
tx := TIME();
(* set last and tx if never started before *)
IF NOT init THEN
init := TRUE;
last := tx;
debounce.PT := T_debounce;
standby := in;
END_IF;
(* debounce input *)
debounce(in := in XOR standby);
Q := debounce.Q;
(* delete outputs if input is inactive *)
IF NOT Q THEN
single := FALSE;
double := FALSE;
triple := FALSE;
status := 110;
END_IF;
(* check for input edge *)
IF Q XOR edge THEN
edge := in;
last := tx;
IF Q THEN state := state + 1; END_IF;
END_IF;
IF (q AND tx - last >= T_short) OR (NOT q AND tx - last >= t_pause) THEN
CASE state OF
1: single := TRUE;
status := 111;
2: double := TRUE;
status := 112;
3: triple := TRUE;
status := 113;
END_CASE;
state := 0;
END_IF;
(* determine if high or low active *)
IF tx - last >= t_reconfig AND standby <> in THEN
standby := in;
END_IF;
die gesamte lib findest du unter
www.oscat.de
das modul click ist dort noch nicht drin es kommt in der version 1.5 anfang märz