# How to simulate a toggle switch

**URL:** <https://forum.xod.io/t/how-to-simulate-a-toggle-switch/3434>\
**Category:** Uncategorized\
**Created:** [February 5, 2020, 5:30pm UTC](https://forum.xod.io/t/how-to-simulate-a-toggle-switch/3434 "2020-02-05T17:30:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jerry4565](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@jerry4565](https://forum.xod.io/u/jerry4565)\
**Post date:** [February 5, 2020, 5:30pm UTC](https://forum.xod.io/t/how-to-simulate-a-toggle-switch/3434/1 "2020-02-05T17:30:55Z")

</div>

Working on my first Patch…so very new to XOD

I would like to simulate a toggle switch: when it is closed send 100 pulses clockwise to a 28BYJ-48 stepper motor then wait for a change in the switch state. When it is open send 100 pulses counter-clockwise to the stepper and again wait for a change in state. The switch input is on D1.

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [February 5, 2020, 6:46pm UTC](https://forum.xod.io/t/how-to-simulate-a-toggle-switch/3434/2 "2020-02-05T18:46:16Z")

</div>

Sounds like you want to use flip-flop node for your toggle and flip-n-times to send the 100 pulses. State of flip-flop will control direction of rotation. flip-n-times restarts count every time button is pressed (flip-flop changes state).

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/2/2f264310ce6a5171d865b13bb0a823a3c86ce868.png)

Both puls… nodes are pulse-on-change.

---

<div class="post-metadata">

**Author:** ![jerry4565](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@jerry4565](https://forum.xod.io/u/jerry4565)\
**Post date:** [February 5, 2020, 9:50pm UTC](https://forum.xod.io/t/how-to-simulate-a-toggle-switch/3434/3 "2020-02-05T21:50:31Z")

</div>

Thank you very much. Your implementation is much simpler than what I had started. I think much of my trouble was not knowing the various nodes. For testing I replaced the switch with a Tweak-Boolean followed by a pulse on change to the TGL input of the F-F. It works great and by adding a few watches I can see how it all works.

Thanks again.
