Professional Documents
Culture Documents
Fiot r18 III Umalwara
Fiot r18 III Umalwara
-Md.Umalawara
UNIT III
What is python?
Features in Python:
There are many features in Python, some of which are discussed below as follows:
1. Free and Open Source
Python language is freely available at the official website and you can download it from the given download
link below click on the Download Python keyword. Download Python Since it is open-source, this means
that source code is also available to the public. So you can download it, use it as well as share it.
2. Easy to code
Python is a high-level programming language. Python is very easy to learn the language as compared to other
languages like C, C#, Javascript, Java, etc. It is very easy to code in the Python language and anybody can
learn Python basics in a few hours or days. It is also a developer-friendly language.
3. Easy to Read
As you will see, learning Python is quite simple. As was already established, Python‟s syntax is really
straightforward. The code block is defined by the indentations rather than by semicolons or brackets.
4. Object-Oriented Language
One of the key features of Python is Object-Oriented programming. Python supports object-oriented language
and concepts of classes, object encapsulation, etc.
5. GUI Programming Support
Graphical User interfaces can be made using a module such as PyQt5, PyQt4, wxPython, or Tk in python.
PyQt5 is the most popular option for creating graphical apps with Python.
6. High-Level Language
Python is a high-level language. When we write programs in Python, we do not need to remember the system
architecture, nor do we need to manage the memory.
7. Extensible feature
Python is an Extensible language. We can write some Python code into C or C++ language and also we can
compile that code in C/C++ language.
8. Easy to Debug:Excellent information for mistake tracing. You will be able to quickly identify and correct
the majority of your program‟s issues once you understand how to interpret Python‟s error traces. Simply by
glancing at the code, you can determine what it is designed to perform.
9. Python is a Portable language
Python language is also a portable language. For example, if we have Python code for windows and if we
want to run this code on other platforms such as Linux, Unix, and Mac then we do not need to change it, we
can run this code on any platform.
10. Python is an Integrated language
Python is also an Integrated language because we can easily integrate Python with other languages like
C, C++, etc.
11. Interpreted Language:
Python is an Interpreted Language because Python code is executed line by line at a time. like other languages
C, C++, Java, etc. there is no need to compile Python code this makes it easier to debug our code. The source
code of Python is converted into an immediate form called bytecode.
12. Large Standard Library
Python has a large standard library that provides a rich set of modules and functions so you do not have to
write your own code for every single thing. There are many libraries present in Python such as regular
expressions, unit-testing, web browsers, etc.
13. Dynamically Typed Language
Python is a dynamically-typed language. That means the type (for example- int, double, long, etc.) for a
variable is decided at run time not in advance because of this feature we don‟t need to specify the type of
variable.
14. Frontend and backend development
With a new project py script, you can run and write Python codes in HTML with the help of some simple tags
<py-script>, <py-env>, etc. This will help you do frontend development work in Python like javascript.
Backend is the strong forte of Python it‟s extensively used for this work cause of its frameworks
like Django and Flask.
In Python, the variable data type does not need to be specified. The memory is automatically allocated to a
variable at runtime when it is given a value. Developers do not need to write int y = 18 if the integer value 15
is set to y. You may just type y=18.
Python Variables
Variable is a name that is used to refer to memory location .
A python varible is also known as an identifier and used to hold value.
# Python program to
# demonstrate numeric value
a=5
print("Type of a: ", type(a))
b = 5.0
print("\nType of b: ", type(b))
c = 2 + 4j
print("\nType of c: ", type(c))
Output:
Type of a: <class 'int'>
Strings in Python are arrays of bytes representing Unicode characters. A string is a collection of one or more
characters put in a single quote, double-quote, or triple-quote. In python there is no character data type, a
character is a string of length one. It is represented by str class.
Creating String
Strings in Python can be created using single quotes or double quotes or even triple quotes.
Python3
# Creating a String
# with single Quotes
String1 = 'Welcome to the World'
print("String with the use of Single Quotes: ")
print(String1)
# Creating a String
# with double Quotes
String1 = "I'm a aruna"
print("\nString with the use of Double Quotes: ")
print(String1)
print(type(String1)
Output:
String with the use of Single Quotes:
Welcome to the World
Python3
# Creating a List
List = []
print("Initial blank List: ")
print(List)
Output:
Initial blank List:
[]
List with the use of String:
['GeeksForGeeks']
List containing multiple values:
Geeks
Geeks
Python Access List Items
In order to access the list items refer to the index number. Use the index operator [ ] to access an item in a list.
In Python, negative sequence indexes represent positions from the end of the array. Instead of having to
compute the offset as in List[len(List)-3], it is enough to just write List[-3]. Negative indexing means
beginning from the end, -1 refers to the last item, -2 refers to the second-last item, etc.
Python3
Output:
Accessing element from the list
Geeks
Geeks
Accessing element using negative indexing
Geeks
Geeks
Note – To know more about Lists, refer to Python List.
Just like a list, a tuple is also an ordered collection of Python objects. The only difference between a tuple and
a list is that tuples are immutable i.e. tuples cannot be modified after it is created. It is represented by a tuple
class.
Creating a Tuple
In Python, tuples are created by placing a sequence of values separated by a „comma‟ with or without the use
of parentheses for grouping the data sequence. Tuples can contain any number of elements and of any
datatype (like strings, integers, lists, etc.). Note: Tuples can also be created with a single element, but it is a
bit tricky. Having one element in the parentheses is not sufficient, there must be a trailing „comma‟ to make it
a tuple.
Python3
# Creating a Tuple
# with nested tuples
Tuple1 = (0, 1, 2, 3)
Tuple2 = ('python', 'geek')
Tuple3 = (Tuple1, Tuple2)
print("\nTuple with nested tuples: ")
print(Tuple3)
Output:
Initial empty Tuple:
()
Python3
# Python program to
# demonstrate accessing tuple
Output:
First element of tuple
1
# Python program to
# demonstrate boolean type
print(type(True))
print(type(False))
print(type(true))
Output:
<class 'bool'>
<class 'bool'>
Traceback (most recent call last):
File "/home/7e8862763fb66153d70824099d4f5fb7.py", line 8, in
print(type(true))
NameError: name 'true' is not defined
Python3
# Creating a Set
set1 = set()
print("Initial blank Set: ")
print(set1)
Output:
Initial blank Set:
set()
Python3
# Creating a set
set1 = set(["Geeks", "For", "Geeks"])
print("\nInitial set")
print(set1)
Output:
Initial set:
{'Geeks', 'For'}
Elements of set:
Geeks For
True
Note – To know more about sets, refer to Python Sets.
Dictionary Data Type in Python
A dictionary in Python is an unordered collection of data values, used to store data values like a map, unlike
other Data Types that hold only a single value as an element, a Dictionary holds a key: value pair. Key-value
is provided in the dictionary to make it more optimized. Each key-value pair in a Dictionary is separated by a
colon : , whereas each key is separated by a „comma‟.
Create a Dictionary
In Python, a Dictionary can be created by placing a sequence of elements within curly {} braces, separated by
„comma‟. Values in a dictionary can be of any datatype and can be duplicated, whereas keys can‟t be repeated
and must be immutable. The dictionary can also be created by the built-in function dict(). An empty dictionary
can be created by just placing it in curly braces{}. Note – Dictionary keys are case sensitive, the same name
but different cases of Key will be treated distinctly.
Python3
# Creating a Dictionary
# with Integer Keys
Dict = {1: 'Geeks', 2: 'For', 3: 'Geeks'}
print("\nDictionary with the use of Integer Keys: ")
print(Dict)
# Creating a Dictionary
# with Mixed keys
Dict = {'Name': 'Geeks', 1: [1, 2, 3, 4]}
print("\nDictionary with the use of Mixed Keys: ")
print(Dict)
# Creating a Dictionary
# with dict() method
Dict = dict({1: 'Geeks', 2: 'For', 3: 'Geeks'})
print("\nDictionary with the use of dict(): ")
print(Dict)
# Creating a Dictionary
# with each item as a Pair
Dict = dict([(1, 'Geeks'), (2, 'For')])
print("\nDictionary with each item as a pair: ")
print(Dict)
Output:
Empty Dictionary:
{}
Python3
# Creating a Dictionary
Dict = {1: 'Geeks', 'name': 'For', 3: 'Geeks'}
Output:
Accessing a element using key:
For
Accessing a element using get:
Geeks
Python Keywords:
Introduction
Keywords in Python are reserved words that can not be used as a variable name, function name, or any
other identifier.
List of all keywords in Python
and as assert break
if import in is
yield
We can also get all the keyword names using the below code.
Python3
Output
The list of keywords is :
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else' ,
'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise',
'return', 'try', 'while', 'with', 'yield']
Output:
The list of keywords is :
[‘False’, ‘None’, ‘True’, ‘and’, ‘as’, ‘assert’, ‘async’, ‘await’, ‘break’, ‘class’, ‘continue’, ‘def’, ‘del’,
‘elif’, ‘else’, ‘except’, ‘finally’, ‘for’, ‘from’, ‘global’, ‘if’, ‘import’, ‘in’, ‘is’, ‘lambda’, ‘nonlocal’, ‘not’,
‘or’, ‘pass’, ‘raise’, ‘return’, ‘try’, ‘while’, ‘with’, ‘yield’]
Control Structures in Python
Control flow refers to the sequence a program will follow during its execution.
Conditions, loops, and calling functions significantly influence how a Python program is controlled.
There are three types of control structures in Python:
1.Sequential - The default working of a program
2.Selection - This structure is used for making decisions by checking conditions and branching
3.Repetition - This structure is used for looping, i.e., repeatedly executing a certain piece of a code
block.
1.Sequential
Sequential statements are a set of statements whose execution process happens in a sequence. The problem
with sequential statements is that if the logic has broken in any one of the lines, then the complete source code
execution will break.
Code
# Python program to show how a sequential control structure works
A program can test many conditions using these selection statements, and depending on whether the given
condition is true or not, it can execute different code blocks.
There can be many forms of decision control structures. Here are some most commonly used control
structures:
1. Only if
2. if-else
3. The nested if
4. The complete if-elif-else
1.Simple if:
If statements in Python are called control flow statements. The selection statements assist us in running a
certain piece of code, but only in certain circumstances. There is only one condition to test in a basic if
statement.
The if statement's fundamental structure is as follows:
Syntax
if <conditional expression> :
The code block to be executed if the condition is True
These statements will always be executed. They are part of the main code.
All the statements written indented after the if statement will run if the condition giver after the if the keyword
is True. Only the code statement that will always be executed regardless of the if the condition is the statement
written aligned to the main code. Python uses these types of indentations to identify a code block of a
particular control flow statement. The specified control structure will alter the flow of only those indented
statements.
2.if-else:
If the condition given in if is False, the if-else block will perform the code t=given in the else block.
Code
# Python program to show how to use the if-else control structure
There are generally two loop statements to implement the repetition structure:
Code
Code
# Python program to show how to execute a while loop
b=9
a=2
# Starting the while loop
# The condition a < b will be checked before each iteration
while a < b:
print(a, end = " ")
a=a+1
print("While loop is completed")
Output:
Loop control statements change execution from their normal sequence. When execution leaves a scope, all
automatic objects that were created in that scope are destroyed. Python supports the following control
statements.
1. Break – Terminates from the loop
2. Continue- It skips the current iteration ececution
3. Pass- Body of the loop is empty
Python Continue
It returns the control to the beginning of the loop.
Python3
Output:
Current Letter : g
Current Letter : k
Current Letter : f
Current Letter : o
Current Letter : r
Current Letter : g
Current Letter : k
Python Break
It brings control out of the loop.
Python3
Output:
Current Letter :
Loops in Python
Python programming language provides the following types of loops to handle looping requirements.
Python While Loop
Until a specified criterion is true, a block of statements will be continuously executed in a Python while loop.
And the line in the program that follows the loop is run when the condition changes to false.
while expression:
statement(s)
In Python, all the statements indented by the same number of character spaces after a programming construct
are considered to be part of a single block of code. Python uses indentation as its method of grouping
statements.
Python3
# prints Hello Geek 3 Times
count = 0
while (count < 3):
count = count+1
print("Hello")
Output:
Hello
Hello
Hello
See this for an example where a while loop is used for iterators. As mentioned in the article, it is not
recommended to use a while loop for iterators in python.
Python3
Output:
List Iteration
geeks
for
geeks
Tuple Iteration
geeks
for
geeks
String Iteration
G
e
e
k
s
Dictionary Iteration
xyz 123
abc 345
Time complexity: O(n), where n is the number of elements in the iterable (list, tuple, string, or dictionary).
Auxiliary space: O(1), as the space used by the program does not depend on the size of the iterable.
We can use a for-in loop for user-defined iterators. See this for example.
Python programming language allows using one loop inside another loop. The following section shows a few
examples to illustrate the concept.
The syntax for a nested for loop statement in Python programming language is as follows:
for iterator_var in sequence:
for iterator_var in sequence:
statements(s)
statements(s)
Syntax of Python Nested while Loop
The syntax for a nested while loop statement in Python programming language is as follows:
while expression:
while expression:
statement(s)
statement(s)
A final note on loop nesting is that we can put any type of loop inside of any other type of loop. For example,
a for loop can be inside a while loop or vice versa.
Python3
Output:
1
22
333
4444
Introduction to raspberry pi
Raspberry pi is the name of the “credit card-sized computer board” developed by the Raspberry pi
foundation, based in the U.K. It gets plugged in a TV or monitor and provides a fully functional computer
capability. It is aimed at imparting knowledge about computing to even younger students at the cheapest
possible price. Although it is aimed at teaching computing to kids, but can be used by everyone willing to
learn programming, the basics of computing, and building different projects by utilizing its versatility.
Raspberry Pi is developed by Raspberry Pi Foundation in the United Kingdom. The Raspberry Pi is a series
of powerful, small single-board computers.
Raspberry Pi is launched in 2012 and there have been several iterations and variations released since then.
Various versions of Raspberry Pi have been out till date. All versions consist of a Broadcom system on a
chip (SoC) with an integrated ARM-compatible CPU and on-chip graphics processing unit (GPU).
The original device had a single-core Processor speed of device ranges from 700 MHz to 1.2 GHz and a
memory range from 256 MB to 1 GB RAM.
To store the operating system and program memory Secure Digital (SD) cards are used. Raspbian OS which
is a Linux operating system is recommended OS by Raspberry Pi Foundation. Some other third party
operating systems like RISC OS Pi. Diet Pi, Kali, Linux can also be run on Raspberry Pi.
Used:
It also provides a set of general purpose input/output pins allowing you to control electronic components for
physical computing and explore the Internet of Things (IOT).
Raspberry pi Diagram :
Raspberry Pi model –
1. pi 1 model B – 2012
2. pi 1 model A – 2013
3. pi 1 model B+ -2014
4. pi 1 model A+ – 2014
5. Pi 2 Model B – 2015
6. Pi 3 Model B- 2016
7. Pi 3 Model B+ -2018
8. Pi 3 Model A+ -2019
9. Pi 4 Model A – 2019
10. Pi Model B – 2020
11. Pi 400 – 2021
Specs of the Computer: – The computer has a quad-core ARM processor that doesn‟t support the same
instruction as an X86 desktop CPU. It has 1GB of RAM, One HDMI port, four USB ports, one Ethernet
connection, Micro SD slot for storage, one combined 3.5mm audio/video port, and a Bluetooth connection.
It has got a series of input and output pins that are used for making projects like – home security cameras,
Encrypted Door lock, etc.
Versatility of Raspberry Pi: – It is indeed a versatile computer and can be utilized by people from all age
groups, it can be used for watching videos on YouTube, watching movies, and programming in languages
like Python, Scratch, and many more. As mentioned above it has a series of I/O pins that give this board the
ability to interact with its environment and hence can be utilized to build really cool and interactive
projects.
Examples of projects: – It can be turned into a weather station by connecting some instruments to
it for check the temperature, wind speed, humidity etc… It can be turned into a home surveillance system
due to its small size; by adding some cameras to it the security network will be ready. If you love reading
books it can also become a storage device for storing thousands of eBooks and also you can access them
through the internet by using this device.
Conclusion: Concluding the article it is convenient to assert that it is a small and powerful computer at a
dirt-cheap rate and can handle most of the task as a desktop computer.
1.Computer in your palm.
2.Single-board computer.
3.Low cost.
4.Easy to access.
Specification :
Basic Architecture :
To the left of the USB ports is an Ethernet port, also known as a network port (Figure
above).You can use this port to connect the Raspberry Pi to a wired computer network using a
cable with what is known as an RJ45 connector on its end. If you look closely at the Ethernet
port, you„ll see two light-emitting diodes (LEDs) at the bottom; these are status LEDs, and let
you know that the connection is working. Just above the Ethernet port, on the left-hand edge
of the Raspberry Pi, is a 3.5 mm audio-visual (AV) jack (Figure 2). This is also known as the
headphone jack, and it can be used for that exact purpose – though you„ll get better sound
connecting it to amplified speakers rather than headphones. It has a hidden, extra feature,
though: as well as audio, the 3.5 mm AV jack carries a video signal which can be connected
to TVs, projectors, and other displays
-High-Definition Multimedia Interface (HDMI) port:
It is the same type of connector you„ll find on a games console, set-top box, and TV. The
multimedia part of its name tells you that it carries both audio and video signals, while high-
definition tells you that you can expect excellent quality. You„ll use this to connect the
Raspberry Pi to your display device, whether that„s a computer monitor, TV, or projector.
-Micro USB power port : which you„ll use to connect the Raspberry Pi to a power
source. The micro USB port is a common sight on smartphones, tablets, and other portable
devices. So you could use a standard mobile charger to power the Pi, but for best results you
should use the official Raspberry Pi USB Power Supply.
Basic Set up for Raspberry Pi
HDMI cable
Monitor.
Key board
Mouse
5volt power adapter for raspberry pi.
LAN cable
Min - 2GB micro sd card
Operating System
Official Supported OS :
1. Raspbian
2. NOOBS
Some of the third party OS :
UBUNTU mate
Snappy Ubuntu core
Windows 10 core
Pinet
Risc OS
Raspberry Pi Setup
Download Raspbian :
Download latest Raspbian image from raspberry pi official site
: https://www.raspberrypi.org/downloads/
Unzip the file and end up with an .img file.
Programming :
Default installed :
Python
C
C++
Java
Scratch
Ruby
Note : Any language that will compile for ARMv6 can be used with raspberry pi.
Applications of Rassberry pi:
1. Media streamer
2. Home automation
3. Controlling BOT
4. VPN
5. Light weight web server for IOT
6. Tablet computer
7. Desktop PC. Using Raspberry Pi, the microSD card, and a power supply, a simple desktop can be
made. ...
8. Wireless print server. ...
9. Media Usage. ...
10. Game Servers. ...
11. Retro Gaming Machine. ...
12. Robot Controller. ...
13. Stop Motion Camera. ...
14. Time-lapse CameraCCombiningge.
1.Power: Pins that are labeled 5.0v supply 5 volts of power and those labeled 3V3 supply 3.3
volts of power. There are two 5V pins and two 3V3 pins.
2.GND: These are the ground pins. There are eight ground pins.
3.Input/Output pins: These are the pins labelled with the # sign, for example, #17, #27, #22,
etc. These pins can be used for input or output.
4.UART: The Universal Asynchronous Receiver/Transmitter allows your Raspberry Pi to be
connected to serial peripherals. The UART pins are labelled TXD and RXD.
5.SPI: The Serial Peripheral Interface is a synchronous serial communication interface
specification used for short distance communication, primarily in embedded systems. The SPI
pins are labeled MOSI, MISO, SCLK, CE0, and CE1.
MISO(Master In Slave Out): Master line for sending data to the master.
MOSI( Master Out Slave In): Slave line for sending data to the Peripherals.
SCK( Serial Clock): Clock generated by master to synchronize data transmission.
CE0( chip Enable 0): to enable or disable devices.
CE1( chip Enable 1): to enable or disable devices.
IoT has evolved from the meeting of wireless technologies, micro- electromechanical
systems (MEMS) and the internet. The Raspberry Pi is a popular choice when developing IoT
products. It offers a complete Linux server with a tiny platform at an incredibly low price.
Actually, the Raspberry Pi is so well-known to IoT that the company has featured several
Internet of Things projects on their site. Here you will find projects and community support
for a range of IoT activities.
Take for example, the World„s First Cloud Texting Enabled Espresso Machine –
powered by Raspberry Pi.Partnered with the Zipwhip cloud texting application, the Raspberry
Pi connects to an espresso machine and allows people to text a message to it that
automatically turns it on and starts brewing beverages. Raspberry Pi can be plugged into a
TV, computer monitor, and it uses a standard keyboard and mouse. It is user-friendly as it can
be handled by all the age groups.
The CPU speed ranges from 700 MHz to 1.2 GHz for the Pi 3 and onboard memory
range from 256 MB to 1 GB RAM. An operating system is stored in the secured digital SD
cards and program memory in either the Micro SDHC or SDHC sizes.
Most boards have one to four USB slots, composite video output, HDMI and a 3.5 mm
phone jack for audio. Some models have WiFi and Bluetooth.
Python program for using PIR sensor:
GND: The Ground pin. Connect this pin to the GND on the GPIO.
VCC: The voltage pin. Connect this pin to one of the 5V pins on the GPIO.
OUT: The output pin. Connect this to one of the Input/Output pins on the GPIO.
previous_state = False #6
current_state = False
while True: #7
time.sleep(0.1) #8
previous_state = current_state #9
current_state = GPIO.input(pirsensor) #10
if current_state != previous_state: #11
if current_state: #12
print("Motion not Detected!") #13
#1: The latest version of Raspbian includes the RPI.GPIO Python library pre- installed, so you
can simply import that into your Python code. The RPI.GPIO is a library that allows your
Python application to easily access the GPIO pins on your Raspberry Pi. The as keyword in
Python allows you to refer to the RPI.GPIO library using the shorter name of GPIO.
#2: The application is going to insert some delays in the execution, so you need to import the
time module.
#3: You declare a variable named pirsensor to indicate the pin number for which the Output
pin on the PIR sensor is connected to the GPIO pin. In this example, it's GPIO pin #4.
#4: There are two ways to refer to the pins on the GPIO: either by physical pin numbers
(starting from pin 1 to 40 on the Raspberry Pi 2/3), or Broadcom GPIO numbers (BCM).
Using BCM is very useful with a ribbon cable (such as the Adafruit T-Cobbler Plus) to
connect the Raspberry Pi to the breadboard. The BCM numbers refer to the labels printed on
the T- Cobbler Plus (see Figure 8). For this example, we're using the BCM numbering
scheme. That means that when we say we're getting the input from pin 4, we're referring to the
pin printed as #4 on the T-Cobbler Plus.
#5: Initialize the pin represented by the variable pin sensor as an input pin. Also, we use a pull-
down resistor (GPIO.PUD_DOWN) for this pin.
#6: There are two variables to keep track of the state of the sensor. #7: We use an infinite
loop to check the state of the sensor repeatedly. #8: Inserts a slight delay of 1 second to the
execution of the program #9: Save the current state of the sensor.
#10: The GPIO.input() function reads the value of the GPIO pin (#4 in this case). When
motion is detected, it returns a value of true.
#11: Compare the previous state and the current state to see if the motion sensor has a change
in state. If there's a change, it means that either the
sensor has just detected motion (when the state changes from false to true), or that the sensor is
resetting itself (when the state changes from true to false) a few seconds after motion has been
detected.
#12: If the current state is true, it means that motion has been detected. #13: Print out the
string ―Motion Detected!‖
# Reading the DHT11 is very sensitive to timings and occasionally the Pi might fail to get a
valid reading. So check if readings are valid.
The DHT11 is probably best suited for projects where rapid data readings are not required and
the environment is not expected to see sudden changes
in temperature or humidity. A
weather station would be an idea
project but a central heating controller may
require something different.
Motors programming:
Import RPi.GPIO
as GPIO from
gpiozero import
Motor
motor1 = Motor(4, 14) # to make it easier to see which pin is
which, you can use Motor(forward=4, backward=14) .
motor2 = Motor(17, 27) # forward=17,
backward =27 motor1.forward()
motor2.for
ward()
motor1.bac
kward()
motor2.bac
kward()
while True: # The Motor class also allows you to reverse the motor„s
direction.
sleep(5
)
motor1.r
everse()
motor2.r
everse()
motor1.stop() # Now stop the
motors motor2.stop()
Buzzer program:
from gpiozero import Button, Lights, buzzer.
buzzer = Buzzer(15)
while True: lights.on()
buzzer.on()
button.wait_for_press()
lights.off()
buzzer.off()
button.wait_for_release()
Program:
while True:
button.wait_for_press()
lights.green.on()
sleep(1)
lights.amber.on( )
sleep(1)
lights.red.on()
sleep(1)
lights.off()