Answered step by step
Verified Expert Solution
Link Copied!

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.setmode(GPIO.LE_POTATO_LOOKUP)
LEDS =(25,18,27,23,26,12,16,20,21)
for led in LEDS:
GPIO.setup(led, GPIO.OUT)
def create_binary_number():
"""Generates a list of 8 bits"""
# Next line is same thing as below but with list comprehension
# num =[randint(0,1) for _ in range(8)]
num =[]
for _ in range(0,8):
num.append(randint(0,1))
return num
def illuminate(bit_list):
"""Illuminates the appropriate LEDS for the provided bit_list"""
for i in range(len(bit_list)):
if bit_list[i]==1:
GPIO.output(LEDS[i], GPIO.HIGH)
else:
GPIO.output(LEDS[i], GPIO.LOW)
def full_adder(Cin, 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 calculate(num1, num2):
"""Takes in two bit lists and adds them. Returns the sum as a bit list"""
Cout =0
Sum =[]
n = len(num1)-1 # get the position of the rightmost bit
while n >=0:
A = num1[n]
B = num2[n]
Cin = Cout
S, Cout = full_adder(Cin, A, B)
sum.insert(0, S)
n -=1
sum.insert(0, Cout)
return sum
################ MAIN PROGRAM ##########################
num1= create_binary_number()
print("", num1)
num2= create_binary_number()
print("+", num2)
sum = calculate(num1, num2)
print("=", sum)
illuminate(sum)
input("Press ENTER key to terminate")
GPIO.cleanup()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases In Networked Information Systems 6th International Workshop Dnis 2010 Aizu Wakamatsu Japan March 2010 Proceedings Lncs 5999

Authors: Shinji Kikuchi ,Shelly Sachdeva ,Subhash Bhalla

2010th Edition

3642120377, 978-3642120374

More Books

Students also viewed these Databases questions

Question

The neurons of the spinal cord are part of the nervous system.

Answered: 1 week ago

Question

What is dividend payout ratio ?

Answered: 1 week ago

Question

Explain the factors affecting dividend policy in detail.

Answered: 1 week ago

Question

6. Identify seven types of hidden histories.

Answered: 1 week ago

Question

What is human nature?

Answered: 1 week ago