Write a short program in python that turns on all leds one


Problem 1: Write a short program in Python that turns on all LEDs, one at a time, in a looping fashion. When an LED is on, it should stay on for 1 second. You will use a while loop to identify the number of loops. You will have a total of 10 loops. Note: n is initialized to 0 (zero). Inside the ‘while' loop, make sure to change the value of n by incrementing by 1. Also, print the iteration count using the following line of code: print("Iteration: ",n). Finish the code block:

#testing a while loop
#import GPIO library
#import time library

import RPi.GPIO as GPIO
import time

#Global variables
N = 0

GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT) #red LED
GPIO.setup(11,GPIO.OUT)#green LED
GPIO.setup(13,GPIO.OUT)#yellow LED

Problem 2: Problem 2 is going to take you some time to think through and write. Although not an extensively long program, it will require anywhere between 20 and 30 lines of code. For this reason, I am only giving you 2 problems for homework. Write a short program in Python that turns on an LED based on the answer to a math calculation. Your program should do the following:

1. Print: Say hello to the end user and tell the end user that the program is designed to add 2 integers.
2. Print: Tell the end user that - if the answer is less than 10, the red LED will turn on.
3. Print: Tell the end user that = if the answer is between (and inclusive) 10 and 30, the yellow LED will turn on.
4. Print: Tell the end user that - if the answer is greater than 30, the green LED will turn on.
5. Prompt the end user for 2 variables inputs, one at a time.
6. Calculate the addition problem.
7. Use an ‘if, else-if' structure as described below.

Note, to ask the end user for an int input value, write the following code:

x = int(input("Enter a number to be added: "))
y= int(input("Enter another number to be added: ))

Note, to use the if-else statement in Python, do the following:
If(answer <= 10):
Elif(answer > 10 or answer < 30):
Elif(answer >= 30):

Solution Preview :

Prepared by a verified Expert
Python Programming: Write a short program in python that turns on all leds one
Reference No:- TGS01416110

Now Priced at $45 (50% Discount)

Recommended (98%)

Rated (4.3/5)