You might want to see how to use switches in DCACLab
<iframe src="https://dcaclab.com/experiments/11993-polarity-switcher/iframe" width="560" height="410" frameborder="0"></iframe>
Cite: Sheikh, F. (2018). Polarity switcher. DCACLab. https://dcaclab.com/circuits/11993-polarity-switcher