# How do I create a redstone circuit whose output depends on it's previous input?

I have two inputs, A and B, and I want them to perform as so:

``````|------------|-----------|--------|
| Prev State | New State | Output |
| A    B     | A   B     |        |
|---------------------------------|
| 0    0     | 0   1     | 1      |
| 0    1     | 0   0     | 0      |
| 0    1     | 1   1     | 1      |
| 1    1     | 0   1     | 0      |
|---------------------------------|
``````

Basically an OR gate works for everything, unless, the previous state was both on, then it needs to be off. Any ideas?

I'm making a light sensor based off of Etho's grass design, and in order to improve its speed, I want to make multiple sensors, and combine their inputs into one.

## SOLUTION

Even though QAdley's answer is the solution to my logic table, it doesn't scale well for multiple inputs. Here is my solution using MBraedley suggestion, substituting the light detector for levers.

In this picture, each lever has both a rising and falling edge detector. All 4 of the rising edge detectors are joined together to form a single output, and all 4 of the falling edge detectors form another.

In this second picture, I use the two outputs as inputs into an RS NOR Latch. The only gotcha is that I had to include a repeater with 2 tics to make the reset input pulse long enough to actually make the NOR Latch work. Then I put an inverter at the end to turn the light on when any switch is turned on, and turn the light off when any switch is turned off.

Thanks everyone for your help, and if you see anything I can improve, let me know!

• You are missing some states – fredley Jun 21 '12 at 15:03
• Can you link to the grass design? Can't figure out what you're talking about. – John Jun 21 '12 at 15:18
• @QAdley I didn't bother with the (1, 0) (A, B) states since they are identical to the (0,1) states. – Daryl Jun 21 '12 at 15:32
• @John I'm using this design specifically since it is the fastest I have found and is more reliable than the Villager version of light detectors: youtube.com/watch?v=zdMA8B50DVk&feature=plcp – Daryl Jun 21 '12 at 15:33

I think what you really want is rising and falling edge detectors. You're only concerned when the first light detector goes high, and when the first light detector goes low, and not so concerned with the state of the other light detectors. From there, you can wire them into an RS NOR latch.

Since simply wiring all the outputs of the light detectors together is equivalent to ORing them, you'll only need one rising edge detector. Have that feed into the SET input of the latch. You'll also have to feed the output of each detector into their own falling edge detector, and from there wire all of them into the RESET input of the latch.

You'll also have to isolate the outputs of the light detectors from each other leading into the rising edge detector, but that's easily accomplished using a repeater.

UPDATE:
After tooling around in creative, there are some additional things that I noticed. First, I had to use a pulse extender on the reset input to the RS NOR latch (I used the sticky piston version). Secondly, the delays I used for the edge detectors is slightly different than what is in the wiki. As with a lot of redstone circuits where timing is important, it's usually necessary to adjust the delay on the repeaters to get everything to work properly. Finally, if combining the signals from the various light detectors before passing them through the edge detectors, you may notice that a set or reset doesn't toggle the latch. This is very unlikely in a light detector since all of them should change states before any change back.

As promised, here are some MCEdit schematics. They aren't the prettiest, but they're functional.

• I think I understand. Each input will need it's own rising and falling edge detector. I then OR all of the rising detectors together, and OR all of the falling edge detectors together, so I end up with one rising detector signal, and one falling detector signal, which I can combine into an RS NOR latch. – Daryl Jun 21 '12 at 16:11
• @Daryl: I would have actually put up a schematic if I had the time showing what I mean. I'll get that drawn later today. You actually only need one rising edge detector. Come to think of it, you can probably get away with one falling edge detector as well. I'll leave that up to you to figure out how as a challenge. For the rising edge detector, attach each of the light outputs to a single redstone line. When one light output goes high, the rest of the line goes high, triggering the edge detector. – MBraedley Jun 21 '12 at 17:34
• I'll actually be going into creative tonight to prototype this myself (probably sans-light detectors; BUD switches freak me out), first doing the design mentioned in the answer, as well as the one I alluded to in the previous comment. MCEdit schematics will follow. – MBraedley Jun 21 '12 at 17:42

You want to use simple shift registers made out of D flip-flops. This simple setup will require 4 flip-flops, 2 to register the inputs, and 2 to hold the previous state.

Basically what you do is load your inputs into these shift registers (one for each input - A and B), which shifts the inputs along one step every tick of your clock. Your shift register will be very simple, only needing two steps, for the current and previous state. That way you always have access to the states, and can wire up the logical table above using simple logic gates.

This approach is easily extendible too - you can add reliability to your daylight detector at any time by adding more states to compare.

• I love how this game is teaching everyone digital circuit design, I feel like I'm back in ESE 204 – BlueRaja - Danny Pflughoeft Jun 21 '12 at 16:10
• I think I'm understanding a little of what your talking about, but in my mind MBraedley's would scale better as I add more inputs. Am I wrong in that assumption? – Daryl Jun 21 '12 at 16:14
• It's up to you! My advice would be to try out both methods, see how they perform, and see what happens when you scale up. Neither of the circuits suggested are that complex, so spend some time playing in creative and see what you come up with! – fredley Jun 21 '12 at 16:15
• I'm not seeing how this works... What is my Clock tick, and how to I convert the registers into my output? – Daryl Jun 21 '12 at 16:51
• @Daryl You'll need to set up a clock, any kind of redstone clock will do, to drive the registers. – fredley Jun 21 '12 at 17:38