SlideShare a Scribd company logo
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
1
MODULE WORKSHOP “ Raspberry Pi3 With Python”
2018
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
2
Secript Python
1. turn-off-led.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(16,GPIO.OUT)
GPIO.output(16,GPIO.HIGH)
time.sleep(2)
GPIO.output(16,GPIO.LOW)
GPIO.cleanup()
Ket:
 Import RPi.GPIO as GPIO Merupakan modul atau library yang digunakan untuk
mengakses GPIO pin pada raspberry pi.
Import Rpi.GPIO as GPIO Is a module or library that is used to access GPIO pins on
raspberry pi.
 Import time juga merupakan library atau modul yang digunakan untuk pengoperasian
terkait dengan waktu.
Import time Is a module or library that is used to access about the time related.
 GPIO setmode(GPIO.BCM) untuk mengaktifkan sistem penomoran pin GPIO.
GPIO setmode(GPIO.BCM) is command to activating numbering system of GPIO pins.
 GPIO.setwarnings(False) memberitahu python untuk mengabaikan perintah jika pin
GPIO sudah digunakan.
GPIO.setwarnings(False) is command to show the python to ignor notice if GPIO pin has
been used.
 GPIO.setup(16,GPIO.OUT) memberitahu python apabila pin GPIO 16 yang akan
digunakan.
GPIO.setup(16,GPIO.OUT) is command to show the pyhton if GPIO pin 16 has been
used.
 GPIO.output(16,GPIO.HIGH) perintah menyalakan lampu LED
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
3
GPIO.output(16,GPIO.HIGH) is command to turn on of the LED lights.
 Time.sleep(2) Perintah untuk menjeda nyala lampu LED
Time.sleep(2) is command to interrupt turn on of the LED lights.
 GPIO.output(16,GPIO.LOW) perintah untuk mematikan lampu LED
GPIO.output(16,GPIO.LOW) is command to turn off the LED lights.
 GPIO.cleanup() perintah untuk memastikan bahwa tidak ada arus listrik di pin GPIO
GPIO.cleanup() is command to makesure if nothing electric current on GPIO pins.
2. blink.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(16,GPIO.OUT)
for i in range(3):
GPIO.output(16, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(16, GPIO.LOW)
time.sleep(0.5)
GPIO.cleanup()
Ket:
 For i in range(3) ini adalah perintah perulangan(for loop) yang nantinya lampu LED
akan berkedip sebanyak 3 kali.
For i in range(3) is command to repeat (for loop) which the LED lights will blink 3 times
 Time.sleep(0.5) waktu jeda lampu
Time.sleep(0.5) is break time of the lights
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
4
3. traffic.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
pinList =[16,20]
SleepTime = 1
for i in pinList:
GPIO.setup(i, GPIO.OUT)
for i in pinList:
GPIO.output(i, GPIO.HIGH)
time.sleep(SleepTime)
GPIO.output(i, GPIO.LOW)
time.sleep(SleepTime)
GPIO.cleanup()
Ket:
 PinList=[16,20] ini adalah perintah List yang akan memberitahu kepada python bahwa pin
GPIO tersebut akan digunakan
PinList=[16,20] this is command to list which give the notice to python if the GPIO pins
has been used.
 SleepTime=1 adalah perintah jeda waktu lampu LED.
SleepTime=1 is command the break time of LED lights.
4. flip_flop.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
5
pinList =[16,20]
SleepTime = 0.2
for i in pinList:
GPIO.setup(i, GPIO.OUT)
try:
while True:
for i in pinList:
GPIO.output(i, GPIO.HIGH)
time.sleep(SleepTime)
GPIO.output(i, GPIO.LOW)
time.sleep(SleepTime)
except KeyboardInterrupt:
pass
GPIO.cleanup()
Ket:
 flip-flop tidak jauh berbeda dengan traffic hanya saja di flip-flop loop-nya terus
menerus(infinite)
Flip-flop not really different from traffic only in the flip-flop looping continuously
(infinite)
 SleepTiem= 0.2 adalah jeda waktu lampu ketika sedang dioprasikan.
SleepTiem=0.2 is the break time of the lights while being operated.
 Except KeyboardInterrup() mengalihkan loop dan akan diterusakn ke GPIO.cleanup
jika ada intrupsi dari keyboard dengan menekan (CRL+C).
Except KeyboardInterrupt is command to switch the loop and will be continue to GPIO.cleanup if
there is an interruption from the keyboard by pressing (CRL+C)
5. piemail.py
import RPi.GPIO as GPIO
import time, math
import smtplib, time
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
6
SMTP_SERVER = 'smtp.gmail.com'
SMTP_PORT = 587
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(16,GPIO.OUT)
GPIO.setup(20,GPIO.OUT)
jawab = "y"
def send_email(username, password, recipient, subject, text):
print(username, password, recipient, subject, text)
smtpserver = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(username, password)
header = 'To:' + recipient + 'n' + 'From: ' + username
header = header + 'n' + 'Subject:' + subject + 'n'
msg = header + 'n' + text + ' nn'
smtpserver.sendmail(username, recipient, msg)
smtpserver.close()
username = "nscmanajemen@gmail.com"
password = "NSC12345"
recipient = "your_to_send_email@gmail.com"
subject = "NSC Workshop"
message_a = "ligth 1 telah menyala "
message_b = "light 1 telah padam"
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
7
message_c = "light 2 telah menyala "
message_d = "light 2 telah padam "
message_e = "light 3 telah menyala "
message_f = "light 3 telah padam "
message_g = "lights 1,2 dan 3 menyala "
message_h = "lights 1,2 dan 3 telah padam "
while (jawab == 'y'):
perintah = input('masukan perintah : ')
if perintah == 'ON led1':
GPIO.output(16,GPIO.HIGH)
send_email(username, password, recipient, subject, message_a)
status = 'led 1 menyala'
elif perintah == 'OFF led1':
GPIO.output(16,GPIO.LOW)
send_email(username, password, recipient, subject, message_b)
status = 'led 1 padam'
elif perintah == 'ON led2':
GPIO.output(20,GPIO.HIGH)
send_email(username, password, recipient, subject, message_c)
status = 'led 2 menyala'
elif perintah == 'OFF led2':
GPIO.output(20,GPIO.LOW)
send_email(username, password, recipient, subject, message_d)
status = 'led 2 padam'
elif perintah == 'ON semua':
GPIO.output(16,GPIO.HIGH)
GPIO.output(20,GPIO.HIGH)
send_email(username, password, recipient, subject, message_g)
status = 'semua led menyala'
elif perintah == 'OFF semua':
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
8
GPIO.output(16,GPIO.LOW)
GPIO.output(20,GPIO.LOW)
send_email(username, password, recipient, subject, message_h)
status = 'semua led padam'
else :
status = 'no perintah'
print ('status : ' + status)
jawab = input("tambah perintah ?")
print ('terimakasih')
Ket:
 import time, math merupakan library atau modul yang digunakan untuk pengoperasian
terkait dengan waktu
Import time, math is library or module to use for related operation with the time.
 import smtplib,time modul yang digunakan untuk mengirim email
Import smtlib,time is module which use for sending email.
 SMTP_SERVER= 'smtp.gmail.com' Protokol yang digunakn untuk mengirim pesan e-
mail antar server.
SMTP SERVER = ‘smtp.gmail com’ is the protocol to used for sending email massage
between server.
 SMTP_PORT = 587 Protokol koneksi yang menghubungkan program
SMTP PORT = 587 is the connection protocol to connect the program
 def sendiri adalah Identitas
Def is identification.
 send-email disebut fungsi
Send-email is funtion
 (username, password, recipient, subject, text) ini di sebut parameter
(Username, password, recepient, subject, text) is parameters.
 Print digunakan untuk mencetak nilai di dalam parameter ke-layar
Print is used for print the value to display in the parameter.
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
9
 smtpserver = smtplib.SMTP(SMTP_SERVER, SMTP_PORT) Untuk mengkoneksikan
dan mengirim email
smtpserver = smtplib.SMTP(SMTP_SERVER, SMTP_PORT) For connecting and
sending email.
 smtpserver.ehlo() memberitahu dan akan mengalihkan printah ketika server tidak
mendukung
smtserver.ehlo() for notice and switch off command when the server not support.
 smtpserver.starttls() mengirim perintah
Smtpserver.starttls() to send the command.
 smtpserver.login(username, password) berfungsi untuk masuk ke akun email.
smtpserver.login(username, password) Function to login email account
 header disini untuk membuat form
Header is use for make a form
 smtpserver.sendmail(username, recipient, msg) perintah yang akan mengirim email
smtpserver.sendmail(username, recipient, msg Command for sending email
 if , elif, else adalah statement di dalam python yang berguna untuk membangun alur
logika pada program
If, elif, else is a statement in python that is useful for building logic paths in the program.
 if adalah suatu kondisi dalam pemrograman yang berarti(jika)
If is condition of the meaning (if) in the program
 elif, juga suatu kondisi dalam pemrograman yang berarti (dan jika)
Elif is condition of the meaning (and if) in the program.
 else juga termasuk dalam kategori kondisi pemrograman yang berarti(selain)
Else is also included in the category of programming conditions which the meaning
(other than)
6. Percabangan.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
Ngoding Study Club 2018
Workshop Raspberry Pi3 With Python
10
GPIO.setup(16,GPIO.OUT)
GPIO.setup(20,GPIO.OUT)
jawab = "y"
while (jawab == 'y') :
perintah = input ('masukan perintah : ')
if perintah == 'ON led1':
GPIO.output(16,GPIO.HIGH)
status = 'led 1 menyala'
elif perintah == 'OFF led1':
GPIO.output(16,GPIO.LOW)
status = 'led 1 padam'
elif perintah == 'ON led2':
GPIO.output(20,GPIO.HIGH)
status = 'led 2 menyala'
elif perintah == 'OFF led2':
GPIO.output(20,GPIO.LOW)
status = 'led 2 padam'
elif perintah == 'ON semua':
GPIO.output(16,GPIO.HIGH)
GPIO.output(20,GPIO.HIGH)
status = 'semua led menyala'
elif perintah == 'OFF semua':
GPIO.output(16,GPIO.LOW)
GPIO.output(20,GPIO.LOW)
status = 'semua led padam'
else :
status = 'no perintah'
print ('status : ' + status)
jawab = input("tambah perintah ? ")
print ('terimakasih')

More Related Content

PPTX
C pythontalk
PDF
PyPy's approach to construct domain-specific language runtime
PDF
Hands on Raspberry Pi - Creative Technologists
PDF
Input and Output
PDF
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
PPT
python-message-0.1.0
PDF
Mpi in-python
PPTX
AI Machine Learning Complete Course: for PHP & Python Devs
C pythontalk
PyPy's approach to construct domain-specific language runtime
Hands on Raspberry Pi - Creative Technologists
Input and Output
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
python-message-0.1.0
Mpi in-python
AI Machine Learning Complete Course: for PHP & Python Devs

What's hot (20)

PDF
The Benefits of Type Hints
PDF
Ry pyconjp2015 turtle
PDF
KEY
Gevent what's the point
PPTX
Android audio system(audioflinger)
PDF
3 1. preprocessor, math, stdlib
PDF
What Are Python Modules? Edureka
PPTX
First look on python
PDF
Apache PIG - User Defined Functions
PDF
Use of an Oscilloscope - maXbox Starter33
PDF
(Www.entrance exam.net)-ignou mca solved assignment 2011
PPT
Python Intro-Functions
PPTX
Python Programming Essentials - M9 - String Formatting
PDF
SymfonyCon 2017 php7 performances
PDF
Metrics ekon 14_2_kleiner
PDF
Control Flow
ODP
What Shazam doesn't want you to know
PDF
Go ahead, make my day
The Benefits of Type Hints
Ry pyconjp2015 turtle
Gevent what's the point
Android audio system(audioflinger)
3 1. preprocessor, math, stdlib
What Are Python Modules? Edureka
First look on python
Apache PIG - User Defined Functions
Use of an Oscilloscope - maXbox Starter33
(Www.entrance exam.net)-ignou mca solved assignment 2011
Python Intro-Functions
Python Programming Essentials - M9 - String Formatting
SymfonyCon 2017 php7 performances
Metrics ekon 14_2_kleiner
Control Flow
What Shazam doesn't want you to know
Go ahead, make my day
Ad

Recently uploaded (20)

PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Business Ethics Teaching Materials for college
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Insiders guide to clinical Medicine.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Pre independence Education in Inndia.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Basic Mud Logging Guide for educational purpose
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
STATICS OF THE RIGID BODIES Hibbelers.pdf
Business Ethics Teaching Materials for college
Open Quiz Monsoon Mind Game Final Set.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
O7-L3 Supply Chain Operations - ICLT Program
The Final Stretch: How to Release a Game and Not Die in the Process.
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Insiders guide to clinical Medicine.pdf
01-Introduction-to-Information-Management.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
human mycosis Human fungal infections are called human mycosis..pptx
Pre independence Education in Inndia.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Basic Mud Logging Guide for educational purpose
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Ad

Module Workshop NSC "Raspberry pi3 with Python" - Sanusi & Sasmitoh RR

  • 1. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 1 MODULE WORKSHOP “ Raspberry Pi3 With Python” 2018
  • 2. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 2 Secript Python 1. turn-off-led.py import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(16,GPIO.OUT) GPIO.output(16,GPIO.HIGH) time.sleep(2) GPIO.output(16,GPIO.LOW) GPIO.cleanup() Ket:  Import RPi.GPIO as GPIO Merupakan modul atau library yang digunakan untuk mengakses GPIO pin pada raspberry pi. Import Rpi.GPIO as GPIO Is a module or library that is used to access GPIO pins on raspberry pi.  Import time juga merupakan library atau modul yang digunakan untuk pengoperasian terkait dengan waktu. Import time Is a module or library that is used to access about the time related.  GPIO setmode(GPIO.BCM) untuk mengaktifkan sistem penomoran pin GPIO. GPIO setmode(GPIO.BCM) is command to activating numbering system of GPIO pins.  GPIO.setwarnings(False) memberitahu python untuk mengabaikan perintah jika pin GPIO sudah digunakan. GPIO.setwarnings(False) is command to show the python to ignor notice if GPIO pin has been used.  GPIO.setup(16,GPIO.OUT) memberitahu python apabila pin GPIO 16 yang akan digunakan. GPIO.setup(16,GPIO.OUT) is command to show the pyhton if GPIO pin 16 has been used.  GPIO.output(16,GPIO.HIGH) perintah menyalakan lampu LED
  • 3. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 3 GPIO.output(16,GPIO.HIGH) is command to turn on of the LED lights.  Time.sleep(2) Perintah untuk menjeda nyala lampu LED Time.sleep(2) is command to interrupt turn on of the LED lights.  GPIO.output(16,GPIO.LOW) perintah untuk mematikan lampu LED GPIO.output(16,GPIO.LOW) is command to turn off the LED lights.  GPIO.cleanup() perintah untuk memastikan bahwa tidak ada arus listrik di pin GPIO GPIO.cleanup() is command to makesure if nothing electric current on GPIO pins. 2. blink.py import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(16,GPIO.OUT) for i in range(3): GPIO.output(16, GPIO.HIGH) time.sleep(0.5) GPIO.output(16, GPIO.LOW) time.sleep(0.5) GPIO.cleanup() Ket:  For i in range(3) ini adalah perintah perulangan(for loop) yang nantinya lampu LED akan berkedip sebanyak 3 kali. For i in range(3) is command to repeat (for loop) which the LED lights will blink 3 times  Time.sleep(0.5) waktu jeda lampu Time.sleep(0.5) is break time of the lights
  • 4. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 4 3. traffic.py import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) pinList =[16,20] SleepTime = 1 for i in pinList: GPIO.setup(i, GPIO.OUT) for i in pinList: GPIO.output(i, GPIO.HIGH) time.sleep(SleepTime) GPIO.output(i, GPIO.LOW) time.sleep(SleepTime) GPIO.cleanup() Ket:  PinList=[16,20] ini adalah perintah List yang akan memberitahu kepada python bahwa pin GPIO tersebut akan digunakan PinList=[16,20] this is command to list which give the notice to python if the GPIO pins has been used.  SleepTime=1 adalah perintah jeda waktu lampu LED. SleepTime=1 is command the break time of LED lights. 4. flip_flop.py import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False)
  • 5. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 5 pinList =[16,20] SleepTime = 0.2 for i in pinList: GPIO.setup(i, GPIO.OUT) try: while True: for i in pinList: GPIO.output(i, GPIO.HIGH) time.sleep(SleepTime) GPIO.output(i, GPIO.LOW) time.sleep(SleepTime) except KeyboardInterrupt: pass GPIO.cleanup() Ket:  flip-flop tidak jauh berbeda dengan traffic hanya saja di flip-flop loop-nya terus menerus(infinite) Flip-flop not really different from traffic only in the flip-flop looping continuously (infinite)  SleepTiem= 0.2 adalah jeda waktu lampu ketika sedang dioprasikan. SleepTiem=0.2 is the break time of the lights while being operated.  Except KeyboardInterrup() mengalihkan loop dan akan diterusakn ke GPIO.cleanup jika ada intrupsi dari keyboard dengan menekan (CRL+C). Except KeyboardInterrupt is command to switch the loop and will be continue to GPIO.cleanup if there is an interruption from the keyboard by pressing (CRL+C) 5. piemail.py import RPi.GPIO as GPIO import time, math import smtplib, time
  • 6. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 6 SMTP_SERVER = 'smtp.gmail.com' SMTP_PORT = 587 GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(16,GPIO.OUT) GPIO.setup(20,GPIO.OUT) jawab = "y" def send_email(username, password, recipient, subject, text): print(username, password, recipient, subject, text) smtpserver = smtplib.SMTP(SMTP_SERVER, SMTP_PORT) smtpserver.ehlo() smtpserver.starttls() smtpserver.ehlo smtpserver.login(username, password) header = 'To:' + recipient + 'n' + 'From: ' + username header = header + 'n' + 'Subject:' + subject + 'n' msg = header + 'n' + text + ' nn' smtpserver.sendmail(username, recipient, msg) smtpserver.close() username = "nscmanajemen@gmail.com" password = "NSC12345" recipient = "your_to_send_email@gmail.com" subject = "NSC Workshop" message_a = "ligth 1 telah menyala " message_b = "light 1 telah padam"
  • 7. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 7 message_c = "light 2 telah menyala " message_d = "light 2 telah padam " message_e = "light 3 telah menyala " message_f = "light 3 telah padam " message_g = "lights 1,2 dan 3 menyala " message_h = "lights 1,2 dan 3 telah padam " while (jawab == 'y'): perintah = input('masukan perintah : ') if perintah == 'ON led1': GPIO.output(16,GPIO.HIGH) send_email(username, password, recipient, subject, message_a) status = 'led 1 menyala' elif perintah == 'OFF led1': GPIO.output(16,GPIO.LOW) send_email(username, password, recipient, subject, message_b) status = 'led 1 padam' elif perintah == 'ON led2': GPIO.output(20,GPIO.HIGH) send_email(username, password, recipient, subject, message_c) status = 'led 2 menyala' elif perintah == 'OFF led2': GPIO.output(20,GPIO.LOW) send_email(username, password, recipient, subject, message_d) status = 'led 2 padam' elif perintah == 'ON semua': GPIO.output(16,GPIO.HIGH) GPIO.output(20,GPIO.HIGH) send_email(username, password, recipient, subject, message_g) status = 'semua led menyala' elif perintah == 'OFF semua':
  • 8. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 8 GPIO.output(16,GPIO.LOW) GPIO.output(20,GPIO.LOW) send_email(username, password, recipient, subject, message_h) status = 'semua led padam' else : status = 'no perintah' print ('status : ' + status) jawab = input("tambah perintah ?") print ('terimakasih') Ket:  import time, math merupakan library atau modul yang digunakan untuk pengoperasian terkait dengan waktu Import time, math is library or module to use for related operation with the time.  import smtplib,time modul yang digunakan untuk mengirim email Import smtlib,time is module which use for sending email.  SMTP_SERVER= 'smtp.gmail.com' Protokol yang digunakn untuk mengirim pesan e- mail antar server. SMTP SERVER = ‘smtp.gmail com’ is the protocol to used for sending email massage between server.  SMTP_PORT = 587 Protokol koneksi yang menghubungkan program SMTP PORT = 587 is the connection protocol to connect the program  def sendiri adalah Identitas Def is identification.  send-email disebut fungsi Send-email is funtion  (username, password, recipient, subject, text) ini di sebut parameter (Username, password, recepient, subject, text) is parameters.  Print digunakan untuk mencetak nilai di dalam parameter ke-layar Print is used for print the value to display in the parameter.
  • 9. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 9  smtpserver = smtplib.SMTP(SMTP_SERVER, SMTP_PORT) Untuk mengkoneksikan dan mengirim email smtpserver = smtplib.SMTP(SMTP_SERVER, SMTP_PORT) For connecting and sending email.  smtpserver.ehlo() memberitahu dan akan mengalihkan printah ketika server tidak mendukung smtserver.ehlo() for notice and switch off command when the server not support.  smtpserver.starttls() mengirim perintah Smtpserver.starttls() to send the command.  smtpserver.login(username, password) berfungsi untuk masuk ke akun email. smtpserver.login(username, password) Function to login email account  header disini untuk membuat form Header is use for make a form  smtpserver.sendmail(username, recipient, msg) perintah yang akan mengirim email smtpserver.sendmail(username, recipient, msg Command for sending email  if , elif, else adalah statement di dalam python yang berguna untuk membangun alur logika pada program If, elif, else is a statement in python that is useful for building logic paths in the program.  if adalah suatu kondisi dalam pemrograman yang berarti(jika) If is condition of the meaning (if) in the program  elif, juga suatu kondisi dalam pemrograman yang berarti (dan jika) Elif is condition of the meaning (and if) in the program.  else juga termasuk dalam kategori kondisi pemrograman yang berarti(selain) Else is also included in the category of programming conditions which the meaning (other than) 6. Percabangan.py import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False)
  • 10. Ngoding Study Club 2018 Workshop Raspberry Pi3 With Python 10 GPIO.setup(16,GPIO.OUT) GPIO.setup(20,GPIO.OUT) jawab = "y" while (jawab == 'y') : perintah = input ('masukan perintah : ') if perintah == 'ON led1': GPIO.output(16,GPIO.HIGH) status = 'led 1 menyala' elif perintah == 'OFF led1': GPIO.output(16,GPIO.LOW) status = 'led 1 padam' elif perintah == 'ON led2': GPIO.output(20,GPIO.HIGH) status = 'led 2 menyala' elif perintah == 'OFF led2': GPIO.output(20,GPIO.LOW) status = 'led 2 padam' elif perintah == 'ON semua': GPIO.output(16,GPIO.HIGH) GPIO.output(20,GPIO.HIGH) status = 'semua led menyala' elif perintah == 'OFF semua': GPIO.output(16,GPIO.LOW) GPIO.output(20,GPIO.LOW) status = 'semua led padam' else : status = 'no perintah' print ('status : ' + status) jawab = input("tambah perintah ? ") print ('terimakasih')