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

  The number of lowercase letters in the file

The number of uppercase letters in the file The number of lowercase letters in the file

  Create mini-python projects or programs

Your assignment is to create mini-Python projects or programs and to run them in the Python-IDLE environment

  Python programming to solve this problem

Write a statement that adds 1 to deansList and prints studentName to standard out if gpa exceeds 3.5.

  Student record due smartsite thursday 1211 1155 pm file

due smartsite thursday 1211 1155 p.m. file names grading.py ltbrgtall prompts for input and all output must match my

  Do a python project and get it running using app engine

Do a python project and get it running using App engine. Something very basic and simple

  Create a cheat commands in the game

Create a cheat commands in the game so player can pick up any item he wants from any location in the map - Display all possible actions you can carry out in game.

  Q1if we knew all the ecological social and competitive

q1if we knew all the ecological social and competitive forces that regulate populations and in reality we couldnt what

  Project title email spam filterabstractanalyze the emails

project title email spam filterabstractanalyze the emails and predict whether the mail is a spam or not a spam.to work

  Console program where you will implement

Create a console program where you will implement coding constructs and variables that are needed for this program and will implement the code within Main and any required static methods.

  Assignment brief you are tasked with improving the code for

assignment brief you are tasked with improving the code for the haunted house game. please read the associated hand-out

  What are the issues assciated with top-down analysis

what are the issues assciated with top-down analysis please explain?

  Q1there has been tremendous development in the arid west of

q1there has been tremendous development in the arid west of the united states over the past few decades creating

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