Hardware Reference
In-Depth Information
The preceding function has been borrowed from the
WonderHowTo
Let's save this function in a separate file and try to call it from another file.
For example, the function has been saved in a file called
parser.py
.
3.
Now, we will import the parser module by opening another file as a module and
implement the e-mail noiier. In this ile, we will blink an LED when there is a
new e-mail. We will start by imporing the
parser
module and
RPi.GPIO
:
import parser
import time
import RPi.GPIO as gpio
We will get started by setting the output pins for the e-mail notifier
example:
gpio.setwarnings(False)
gpio.setmode(gpio.BCM)
gpio.setup(17,gpio.OUT)
Now, we'll check for new e-mails and blink an LED if there is an unread e-mail:
while True:
mail = parser.mail() #check for email
count = 0
if mail>0: #print for new emails
print(mail)
print("new emails \n")
while count<10:
count += 1
gpio.output(17,gpio.HIGH) #blink LED if there are new
emails
time.sleep(1)
gpio.output(17,gpio.LOW)
time.sleep(1)
gpio.output(17,gpio.LOW) #set LED to low
else:
time.sleep(10) #repeat cycle for 10 seconds