component blink "Manage the blinking function"; pin in bit enable; // activate the blinking function pin in signed on_time; // duration "on" period for the blinking in units of time base selection pin in signed off_time; // duration "off" period for the blinking in units of time base selection pin io bit on_time_done; // bit "on time done" at 1 if the "on time" is elapsed pin io bit off_time_done; // bit "off time done" at 1 if the "off time" is elapsed pin io signed on_time_count; // "on time" elapsing count pin io signed off_time_count; // "off time" elapsing count pin out bit blink_off; // blink off output active when the "off time" is elapsing pin out bit blink_on; // blink on output active when the "on time" is elapsing param rw signed on_time_base = 1; // time base selection 0=1ms - 1=0.01s - 2=0.1s - 3=1s param rw signed off_time_base = 1; // time base selection 0=1ms - 1=0.01s - 2=0.1s - 3=1s description """ This component manage the blinking function starting with the "on time" counting and when the "on time" is elapsed the "off time" counting is working. Time base for the "on time" and the "off time" duration is selectable independently."""; notes """ enable : activate the blinking function (input pin) ; on_time_base : time base selection 0=1ms - 1=0.01s - 2=0.1s - 3=1s (parameter) ; on_time : duration "on" period for the blinking in units of time base selection (input pin) ; off_time_base : time base selection 0=1ms - 1=0.01s - 2=0.1s - 3=1s (parameter) ; off_time : duration "on" period for the blinking in units of time base selection (input pin) ; blink_on : active when the "on time" is elapsing ; blink_off : active when the "off time" is elapsing . """; function _ nofp; author "Alex Chiosso - 2014"; license "GPL"; // indicates GPL v2 or later ;; FUNCTION(_) { int on_time_preset_calc , off_time_preset_calc ; if (on_time_base==0) {on_time_preset_calc = abs(on_time);} else if (on_time_base==1) {on_time_preset_calc = abs(on_time * 10);} else if (on_time_base==2) {on_time_preset_calc = abs(on_time * 100);} else if (on_time_base==3) {on_time_preset_calc = abs(on_time * 1000);} else {on_time_preset_calc = abs(on_time);} if (off_time_base==0) {off_time_preset_calc = abs(off_time);} else if (off_time_base==1) {off_time_preset_calc = abs(off_time * 10);} else if (off_time_base==2) {off_time_preset_calc = abs(off_time * 100);} else if (off_time_base==3) {off_time_preset_calc = abs(off_time * 1000);} else {off_time_preset_calc = abs(off_time);} if (enable) { if (off_time_done) {on_time_count = 0 , off_time_done = 0;} if (!on_time_done) {on_time_count = on_time_count + 1;} if (on_time_count >= on_time_preset_calc) {on_time_done = 1;} else {on_time_done = 0;} blink_on = !on_time_done; blink_off = on_time_done; } else {on_time_count = 0 , on_time_done = 0 , blink_on = 0 , blink_off = 0;} if (enable && on_time_done) { {off_time_count = off_time_count + 1;} if (off_time_count >= off_time_preset_calc) {off_time_done = 1;} else {off_time_done = 0;} } else {off_time_count = 0 , off_time_done = 0;} }