Write a short program in python that turns on all leds

Assignment Help Python Programming
Reference no: EM131070302

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):

Reference no: EM131070302

Questions Cloud

Induced current in the inner loop : A small, 1.80-mm-diameter circular loop with R = 1.40×10-2 Ω is at the center of a large 120-mm-diameter circular loop. Both loops lie in the same plane. The current in the outer loop changes from +1.0A to -1.0A in 0.100 s. What is the induced cur..
Index of refraction of the material : Nicholas and Louis have an unknown clear solid that has a 36 degree critical angle for total internal reflection. What is the index of refraction of the material?
How much would she make for hours of work : Kelko made $198 for 11 hours of work. At the same rate, how much would she make for 8 hours of work
Spring pulls in the horizontal direction : Find the coefficient of kinetic friction between a 4.55-kg block and the horizontal surface on which it rests if a 93.0-N/m spring must be stretched by 6.30 cm to pull it with constant speed. Assume that the spring pulls in the horizontal directio..
Write a short program in python that turns on all leds : 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.
Scientific research in the field of psychology : Discuss the need for scientific research in the field of psychology. How does psychological research obtain and use empirical evidence - Issues related to sexual orientation have been at the forefront of the current political landscape.
How the gravitational constant was first measured : Who first measured G? Where and when? How was this constant related to Sir Isaac Newton (Newton did not measure G)?
How does using strings like integers alter the o-notation : How does using strings instead of simple types like integers alter the O-notation of operations? Is the ADT given in program 4.7 a first-class ADT? Explain your answer.
Present data in attractive reports and forms : With a recent growth in business, Great Outdoors Tours has developed a database in Access 2013 to organize its records. The company would like your help with presenting data in attractive reports and forms that highlight certain information.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd