import machine
from machine import Pin
#ENTRADA
B_1_IN = Pin(18, Pin.IN, Pin.PULL_UP)
B_2_IN = Pin(2, Pin.IN, Pin.PULL_UP)
A_1_IN = Pin(19, Pin.IN, Pin.PULL_UP)
A_2_IN = Pin(4, Pin.IN, Pin.PULL_UP)
#SALIDA
S_1_OUT = Pin(14, Pin.OUT)
S_2_OUT = Pin(12, Pin.OUT)
C_OUT = Pin(13, Pin.OUT)
while True:
B_1 = B_1_IN.value()
B_2 = B_2_IN.value()
A_1 = A_1_IN.value()
A_2 = A_2_IN.value()
#SUMA:
# C1
# A1 B1
# + A2 B2
# -------
# C2 |S2 S1
#HALF-ADDLER
S_1 = (not B_1 and B_2) or (B_1 and not B_2)
C_1 = (B_1 and B_2)
#FULL-ADDLER
Xor = (not A_1 and A_2) or (A_1 and not A_2)
S_2 = (not C_1 and Xor) or (C_1 and not Xor)
C_2 = (A_1 and A_2) or (A_1 and C_1) or (A_2 and C_1)
S_1_OUT.value(S_1)
S_2_OUT.value(S_2)
C_OUT.value(C_2)