import machine
from machine import Pin

def xorFn(X,Y):
    return ((not X) and Y) or (X and (not Y)) 

def mayoria(X,Y,Z):
    return (X and Y) or (X and Z) or (Y and Z)

sliderAUno = Pin (4,Pin.IN,Pin.PULL_UP)
sliderACero = Pin (2,Pin.IN,Pin.PULL_UP)

sliderBUno = Pin (21,Pin.IN,Pin.PULL_UP)
sliderBCero = Pin (18,Pin.IN,Pin.PULL_UP)

ledRojo = Pin(12, Pin.OUT)
ledVerde = Pin(13, Pin.OUT)
ledAzul = Pin(14, Pin.OUT)

while True:
    aUno = sliderAUno.value()
    aCero = sliderACero.value()
    bUno = sliderBUno.value()
    bCero = sliderBCero.value()
    
    resultCero = xorFn(aCero,bCero)
    carrySemiSumador = aCero and bCero

    resultUno = xorFn( xorFn(aUno,bUno),carrySemiSumador)
    carryResultado = mayoria(aUno,bUno,carrySemiSumador)

    ledRojo.value(resultCero)
    ledVerde.value(resultUno)
    ledAzul.value(carryResultado)
    #print("R0 "+str(bool(resultCero))+ " R1 "+ str(bool(resultUno))+" C "+ str(bool(carryResultado)))