import machine
from machine import Pin
def funcionXor(X,Y):
return ((not X and Y) or (X and not Y))
def esMayoria(X,Y,Z):
return ((X and Y) or (X and Z) or (Y and Z))
ledRojo = Pin(12,Pin.OUT)
ledAzul = Pin(14,Pin.OUT)
sliderA = Pin(4,Pin.IN,Pin.PULL_UP)
sliderB = Pin(2,Pin.IN,Pin.PULL_UP)
sliderC = Pin(15,Pin.IN,Pin.PULL_UP)
while True:
A = sliderA.value()
B = sliderB.value()
C = sliderC.value()
sumador = funcionXor(funcionXor(A,B),C)
#XOR = (NotA and B) or (A and notB)
carry = esMayoria(A,B,C)
ledRojo.value(sumador)
ledAzul.value(carry)
print("A="+str(bool(A))+" B="+str(bool(B))+" S="+str(bool(sumador))+" C="+str(bool(carry)))