Ok BB

First of all ...

explain with clear words what your device has to do :

from which inputs (w/ details ) to which outputs ( w/details ) ...

50% of the work is here ...

Alain

PS: and stop thinking " C " ... you must think " Basic " now ! ( ROFL)