Last active
May 20, 2019 03:39
-
-
Save idriszmy/29bd6513eea78f2b5d437cfc8398d473 to your computer and use it in GitHub Desktop.
Menghasilkan bunyi daripada pembaz (Contoh 1).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Fungsi kod: Menghasilkan bunyi daripada pembaz (Contoh 1). | |
# Penulis: Idris Zainal Abidin | |
# Blog: https://idrisz.my | |
# Kemaskini: 20 Mei 2019 | |
# | |
from gpiozero import LED, Buzzer # Import fungsi LED dan Buzzer | |
# daripada pustaka gpiozero | |
from time import sleep # Import fungsi sleep dari pustaka time | |
led8 = LED(19) # led8 bersambung pada GPIO19 | |
buzzer = Buzzer(26) # Pembaz disambungkan pada GPIO26 | |
# Fungsi beep memerlukan 3 pembolehubah | |
# Pembolehubah 1: Tempoh isyarat HIGH (bunyi) dalam saat | |
# Pembolehubah 2: Tempoh isyarat LOW (senyap) dalam saat | |
# Pembolehubah 3: Berapa kali ulang? | |
buzzer.beep(0.1, 0.1, 2) | |
try: | |
while True: # Pernyataan berulang utama | |
print("Jom Belajar Bersama Idris di idrisz.my") # Paparkan mesej di Python Shell | |
led8.on() # led8 menyala | |
sleep(2) # Tunggu 2 saat | |
led8.off() # led8 padam | |
sleep(2) # Tunggu 2 saat | |
except KeyboardInterrupt: | |
led8.off() # led8 padam | |
buzzer.off() # Pembaz senyap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment