Grim
02-20-2011, 04:16 PM
I didn't find this anywhere else when I myself couldn't figure it out, but now that I know how and still don't see a tutorial I figure I might as well make one.
This a simplistic yet very accurate way to create a code sequence such as the famous Konami Code, but it can also apply to other inputs besides buttons:
1. Make an XOR gate with an input for each output that will reset the sequence if triggered at the wrong time. Keep in mind that these do not need to be part of the sequence in order to reset it, which is why I linked every button and joystick on the controllinator to the XOR gate in the figure below. Now make a counter with a target count of 1 and connect its output to its own reset input. Connect the XOR gate to the counter's main input. If your XOR gate has any inputs that can be negative (such as down or left on the joysticks/d-pad), you'll want to run it through two NOT gates first in order to get the absolute value as seen in the figure below. Without those NOT gates a negative input would not be able to trigger the counter. You should end up with an output that activates momentarily when any of the buttons are pressed:
http://www.orangemarble.net/lbp/1.jpg
2. Place a selector with the port number equal to the amount of inputs in your sequence plus one, and link the counter from step 1 to its first input. Place an AND gate for each input in the sequence and link each output on the selector to each AND gate in order from #1 to whichever output comes second-to-last. Now connect each AND gate's output back to the selector so that the AND gate taking selector output #1 loops back to selector input #2, #2 to #3, etc. I recommend color coding the AND gates to make the sequence a bit more readable. This is what it looks like with 4 inputs:
http://www.orangemarble.net/lbp/2.jpg
3. Now simply connect each button to the AND gates going in sequence. In my example I use Up, Down, Triangle, and Cross in that order, which requires the use of a direction splitter. Hook the last output on the selector to whatever you want to activate when the code is completed. You now have a fully functional code sequence:
http://www.orangemarble.net/lbp/3.jpg
4. You may notice that you can still cheat the code sequence by holding one button down that isn't in the sequence and randomly mashing on the rest. This is because of a stupid oversight I noticed only after I took my screenshots, but you can fix it simply by moving the AND gates into a microchip and linking the XOR gate's output to it:
http://www.orangemarble.net/lbp/6.jpg
5. (optional) If you want to make it easier to tell which AND gate has which button assigned to it, you can use microchips instead of AND gates altogether. Have the selector turn on the microchip which has a circuit node for the next button passing through it. This functions very much the same as an AND gate but the wires should be easier to read while their respective microchip is open. You can also reverse this and have the microchip activate when the button is pressed, then pass the selector's output through it instead. This can save you some microchips whenever the same button is used multiple times in the sequence, but it can be a little more confusing since there won't be a colored microchip for those parts of the sequence anymore. Note that this example can still be cheated without being inside the microchip from step 4:
http://www.orangemarble.net/lbp/4.jpg
6. Any buttons that appear twice in a row should first be run through a counter like the one in step 1. Here is what it'd look like if Down in the sequence was replaced with another instance of Up:
http://www.orangemarble.net/lbp/5.jpg
That should leave you with a mostly perfect code sequence using one button at a time. Let me know if there's any amendments I should make, or if I'm overlooking a far better way to do it. :p
This a simplistic yet very accurate way to create a code sequence such as the famous Konami Code, but it can also apply to other inputs besides buttons:
1. Make an XOR gate with an input for each output that will reset the sequence if triggered at the wrong time. Keep in mind that these do not need to be part of the sequence in order to reset it, which is why I linked every button and joystick on the controllinator to the XOR gate in the figure below. Now make a counter with a target count of 1 and connect its output to its own reset input. Connect the XOR gate to the counter's main input. If your XOR gate has any inputs that can be negative (such as down or left on the joysticks/d-pad), you'll want to run it through two NOT gates first in order to get the absolute value as seen in the figure below. Without those NOT gates a negative input would not be able to trigger the counter. You should end up with an output that activates momentarily when any of the buttons are pressed:
http://www.orangemarble.net/lbp/1.jpg
2. Place a selector with the port number equal to the amount of inputs in your sequence plus one, and link the counter from step 1 to its first input. Place an AND gate for each input in the sequence and link each output on the selector to each AND gate in order from #1 to whichever output comes second-to-last. Now connect each AND gate's output back to the selector so that the AND gate taking selector output #1 loops back to selector input #2, #2 to #3, etc. I recommend color coding the AND gates to make the sequence a bit more readable. This is what it looks like with 4 inputs:
http://www.orangemarble.net/lbp/2.jpg
3. Now simply connect each button to the AND gates going in sequence. In my example I use Up, Down, Triangle, and Cross in that order, which requires the use of a direction splitter. Hook the last output on the selector to whatever you want to activate when the code is completed. You now have a fully functional code sequence:
http://www.orangemarble.net/lbp/3.jpg
4. You may notice that you can still cheat the code sequence by holding one button down that isn't in the sequence and randomly mashing on the rest. This is because of a stupid oversight I noticed only after I took my screenshots, but you can fix it simply by moving the AND gates into a microchip and linking the XOR gate's output to it:
http://www.orangemarble.net/lbp/6.jpg
5. (optional) If you want to make it easier to tell which AND gate has which button assigned to it, you can use microchips instead of AND gates altogether. Have the selector turn on the microchip which has a circuit node for the next button passing through it. This functions very much the same as an AND gate but the wires should be easier to read while their respective microchip is open. You can also reverse this and have the microchip activate when the button is pressed, then pass the selector's output through it instead. This can save you some microchips whenever the same button is used multiple times in the sequence, but it can be a little more confusing since there won't be a colored microchip for those parts of the sequence anymore. Note that this example can still be cheated without being inside the microchip from step 4:
http://www.orangemarble.net/lbp/4.jpg
6. Any buttons that appear twice in a row should first be run through a counter like the one in step 1. Here is what it'd look like if Down in the sequence was replaced with another instance of Up:
http://www.orangemarble.net/lbp/5.jpg
That should leave you with a mostly perfect code sequence using one button at a time. Let me know if there's any amendments I should make, or if I'm overlooking a far better way to do it. :p