"""
1er Parcial, 2a. parte
Comparador de 4 bits
Se leerá un número (A), de 4 bits, de las terminales:
GPIO3, GPIO2, GPIO1 y GPIO0 (GPIO es el menos significativo)
Y otro número (B), también de 4 bits, de las terminales:
GPIO7, GPIO6, GPIO5 y GPIO4 (GPI4 es el menos significativo)
Si A > B se enciende el LED de GPIO16
Si A = B se enciende el LED de GPIO17
Si A < B se enciende el LED de GPIO18
Nombre: Jesus Antonio Rosario Hernandez
"""
from machine import Pin
import time
pines1 = [0, 1, 2, 3]
pines2 = [4, 5, 6, 7]
numeroA = list()
numeroB = list()
for i in range(4):
numeroA.append(Pin(pines1[i], Pin.IN, Pin.PULL_UP))
numeroB.append(Pin(pines2[i], Pin.IN, Pin.PULL_UP))
led1 = Pin(16, Pin.OUT)
led2 = Pin(17, Pin.OUT)
led3 = Pin(18, Pin.OUT)
while True:
tmp1 = ""
tmp2 = ""
for i in range(4):
tmp1 = str(numeroA[i].value()) + tmp1
tmp2 = str(numeroB[i].value()) + tmp2
bin1 = int(tmp1, 2)
bin2 = int(tmp2, 2)
if bin1 > bin2:
print(str(bin1) + " ES MAYOR QUE " + str(bin2))
led1.value(1)
led2.value(0)
led3.value(0)
elif bin1 < bin2:
print(str(bin1) + " ES MENOR QUE " + str(bin2))
led1.value(0)
led2.value(0)
led3.value(1)
else:
print(str(bin1) + " ES IGUAL QUE " + str(bin2))
led1.value(0)
led2.value(1)
led3.value(0)
time.sleep_ms(800)