So for my circuit, I have set up a simple game of rock paper scissors. I have the actual gameplay of rock paper scissors working, where it will correctly choose the winner and light up corresponding leds on an icestick. The way the game works is that player one picks one of the top three inputs (Rock, paper, scissors from top to bottom) and player 2 picks at the same time. The resulting circuit will lead to one of the three outputs, with the top output being a player 1 win, the middle output being a draw, and the bottom output being a player 2 win. What I'm trying to add is a win tracking system, which would be done with having 2 leds for each player. When a player wins once the circuit would light the first led and after the second win the circuit would light the 2nd led. I'm currently lost on how to implement a way for the circuit to essentially have an if/else statement to check if the first led is getting input in order to light the second. Can anyone offer any advice for this? 
- 41
- 3
-
3I'm not entirely sure what you are trying to achieve, but (1) you will probably want to latch or capture the input so that it cannot be changed until cleared and (2) you will also want to count the wins (a latch) and then decode the count to the LEDs. Seems like that to me. It sounds as though you don't need to implement the if because I seem to gather you already have that working. – jonk May 24 '21 at 19:18
-
3why not just use a counter to count the output transitions (low to high or high to low)? – Rodo May 24 '21 at 20:57
3 Answers
The hardware equivalent of an if/else is a multiplexer.
if select_input == 0
output = input_0
else
output = input_1
- 31,521
- 5
- 30
- 67
The circuit you drew is purely combinational. It assumes that one of the top three inputs is asserted, and one of the bottom three. This is fine for learning basic combinational logic, but it's not what you'd really want to do for this. Fine for now.
What you're really asking to do though is to track the history of winners. There's nothing special about this, no "if/else" required. The control for the 2nd LED would be "1st LED lit AND new win" or something like that.
As a commenter mentioned, you need sequential logic to do this. At least one flip-flop per player. Is this for a class? If so, has sequential logic been covered? If not, have you learned it on your own? I need more info about your level of knowledge before I can update this...
- 614
- 1
- 4
- 6
This should do it.
First clock pulse in clocks a high through to Q output of first flipflop and lights first LED.
Second clock pulse in clocks high through to Q output of second flipflop and lights second LED (first LED stays lit).
Pressing SW1 resets both flipflops and turns both LEDs off at end of game.
C1 in conjunction with R4 is a power-on-reset circuit which ensures both LEDs are off when power is first applied. D3 ensures that the reset inputs are not taken too far negative at power off.
It is very important to include debounce circuitry on the players' switch inputs so that only single clean pulses are applied to the flipflops' clock inputs.
EDIT
Sorry, I think I was being a bit slow. After re-reading your question it seems apparent that you require the first LED to switch off when the second LED comes on. On further consideration you may think that is a better "score" method to have both LEDs lit to reflect a tally of two wins as opposed to having just the second LED on.
If after further reflection you are still of the opinion that it is better to extinguish the first LED when illuminating the second one then you may wish to consider the circuit below as a feasible solution. This circuit uses "basic logic gates" and a couple of D-Type flipflops, configured as a synchronous counter, to ensure that the first LED goes off when the second LED comes on. The circuit has an added advantage in that it locks the winning player out when the second LED is on, that is to say after 2 wins by one player the circuit will no longer respond to further clock pulses until reset.
As with the first circuit, it is very important to debounce the players' input switches to avoid multiple transitions on the clock inputs.

