-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsr_latch.py
29 lines (23 loc) · 971 Bytes
/
sr_latch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import random
from component import Component
from not_gate import NotGate
from or_gate import OrGate
from and_gate import AndGate
class SrLatch(Component):
def __init__(self,input_data):
self.INPUT_LENGTH = 2
super().__init__()
self.not_gate = NotGate([False])
self.or_gate = OrGate([False,False])
self.and_gate = AndGate([self.or_gate.output, self.not_gate.output])
self.output = self.and_gate.output
self.update(input_data)
#First is set, second is reset
def update(self,input_data):
self.clear_input(input_data)
#-----------Logic-------------#
self.not_gate.update([self.input[1]])
self.or_gate.update([self.and_gate.output[0],self.input[0]])
self.and_gate.update([self.or_gate.output[0],self.not_gate.output[0]])
self.or_gate.update([self.and_gate.output[0],self.input[0]])
self.output = self.and_gate.output