Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import pineworkslabs.RPi as GPIO from random import randint GPIO = ' ' # don't type this line GPIO.setmode ( GPIO . LE _ POTATO _
import pineworkslabs.RPi as GPIO
from random import randint
GPIO # don't type this line
GPIO.setmodeGPIOLEPOTATOLOOKUP
LEDS
for led in LEDS:
GPIO.setupled GPIO.OUT
def createbinarynumber:
Generates a list of bits"""
# Next line is same thing as below but with list comprehension
# num randint for in range
num
for in range:
num.appendrandint
return num
def illuminatebitlist:
Illuminates the appropriate LEDS for the provided bitlist"""
for i in rangelenbitlist:
if bitlisti:
GPIO.outputLEDSi GPIO.HIGH
else:
GPIO.outputLEDSi GPIO.LOW
def fulladderCin A B:
Implements a full adder to add the arguments"""
# This is HOMEWORK. MUST USE BITWISE OPERATORS LIKE & ~ NOT THE WORDS FOR THEM
return S Cout
def calculatenum num:
Takes in two bit lists and adds them. Returns the sum as a bit list"""
Cout
Sum
n lennum # get the position of the rightmost bit
while n :
A numn
B numn
Cin Cout
S Cout fulladderCin A B
sum.insert S
n
sum.insert Cout
return sum
################ MAIN PROGRAM ##########################
num createbinarynumber
print num
num createbinarynumber
print num
sum calculatenum num
print sum
illuminatesum
inputPress ENTER key to terminate"
GPIO.cleanup
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started