from machine import Pin
from time import sleep
# ============================================================
# ECEN 218 - Digital Logic Laboratory
# Lab 0: Virtual Digital Laboratory and Pico Introduction
#
# The Raspberry Pi Pico is being used as a DIGITAL TEST SYSTEM.
#
# GP2 -> circuit input A
# GP3 -> circuit input B
# GP4 <- circuit output Y
#
# The Pico will automatically generate every possible
# two-input combination and measure the circuit output.
# ============================================================
A = Pin(2, Pin.OUT)
B = Pin(3, Pin.OUT)
Y = Pin(4, Pin.IN)
print()
print("ECEN 218 - Automated Digital Logic Test")
print()
passed = True
print(" A B | Expected Measured")
print("------+-------------------")
for a in [0, 1]:
for b in [0, 1]:
# Apply the input combination
A.value(a)
B.value(b)
# Wait briefly before measuring
sleep(0.5)
# Read the actual circuit output
measured = Y.value()
# ====================================================
# STUDENT TASK
#
# The circuit in this starter project is an AND gate.
#
# The expression below does NOT yet correctly describe
# the expected output of the circuit.
#
# Replace the expression with one that correctly
# computes the AND function using variables a and b.
# ====================================================
# Useful Python logic operators:
# & AND
# | OR
# ^ XOR
# not NOT
expected = int(not (a | b))
# Print the result
print(
" %d %d | %d %d"
% (a, b, expected, measured)
)
# Check the circuit
if measured != expected:
passed = False
print()
print("--------------------------------")
if passed:
print("TEST PASSED")
else:
print("TEST FAILED")
print("--------------------------------")
print()
# Keep the simulator running so the final signals remain
# available for observation.
while True:
sleep(1)