from machine import Pin
import time
# Define input switches
Sw1 = Pin(14, Pin.IN, Pin.PULL_DOWN) # Input A
Sw2 = Pin(15, Pin.IN, Pin.PULL_DOWN) # Input B
# Define output LEDs
led_and = Pin(0, Pin.OUT)
led_or = Pin(1, Pin.OUT)
led_not = Pin(2, Pin.OUT)
while True:
a = Sw1.value() # Read input A
b = Sw2.value() # Read input B
# Logic gate operations
and_result = a and b
or_result = a or b
not_result = int(not a) # NOT applied to A
# Display output on LEDs
led_and.value(and_result)
led_or.value(or_result)
led_not.value(not_result)
# Print results in serial monitor
print("A = {}, B = {}, AND = {}, OR = {}, NOT(A) = {}".format(a, b, and_result, or_result, not_result))
time.sleep(1)