How do I create an RS-NOR latch with a toggle input in addition to the standard "On" and "Off" buttons? [JAVA EDITION]
Upon request from multiple moderators/experts, this question has been split into two identical questions, one for each of the two main versions of Minecraft. This question is for solutions for Java Edition. If you have a solution for Bedrock Edition, please post it here.
I am creating a redstone contraption that is based off an RS-NOR latch and a T-flip-flop at once.
The contraption needs to have three pulse-based inputs and one output.
Here are the inputs and their descriptions of what they should do:
- "On" button: Turn the output on, or keep it on if it is already on.
- "Off" button: Turn the output off, or keep it off if it is already off.
- "Toggle" button: Toggle the state of the output, no matter what state it was in before.
The toggle button should provide only a temporary inversion, with the next button press acting as normal.
Here are the questions I would like to have answered:
- Should my redstone contraption be based off a T-flip flop, a RS-NOR latch, or neither?
- What is the most compact way to construct a redstone contraption like this?
Please include images with your solution.
What you're looking for is still going to be based primarily around an RS latch, with a couple of AND gates to make the toggle line work properly. For this, the circuit diagram looks like this:
Breaking it down, you have an RS latch hooked up as normal. From there, you need the output and an inverted output to control two AND gates that control which input the Toggle is meant to control. That is, if the RS state is on, your toggle should control the off side of the RS latch.
I'm sure this could be done more cleanly, but the circuit I came up with is this:
Note that in the above there are sticky pistons underneath the gold blocks which act as AND gates, and a redstone repeater underneath the diamond block to keep the signal from the repeater on the Reset line from being directly connected to the Output line. Here's a closer look at that portion of the circuit:
Maybe there's a compact way to do exactly what you want in one circuit element, but you can also just use a regular RS-NOR latch and then a circuit element that inverts signals on request.
I tried out a bunch of complex ideas around this, until I realised that this comes down to a simple logic gate, with this logic table:
┌───┬───┬───┐
│IN1│IN2│OUT│
├───┼───┼───┤
│ 0 │ 0 │ 0 │
│ 0 │ 1 │ 1 │
│ 1 │ 0 │ 1 │
│ 1 │ 1 │ 0 │
└───┴───┴───┘
Therefore, what you want is an XOR
gate. The Minecraft wiki has tutorials for those: https://minecraft.gamepedia.com/Mechanics/Redstone/Logic_circuit#XOR_gate (archive)
Just so this is a complete answer (and not considered a link-only answer), here's a screenshot of one of the alternative designs. Of course you'll realistically want to compare the different designs on the wiki and pick one that works best for your situation.