diff options
| author | Abdellah El Morabit <nsrddyn@gmail.com> | 2024-11-05 09:24:48 +0100 |
|---|---|---|
| committer | Abdellah El Morabit <nsrddyn@gmail.com> | 2024-11-05 09:24:48 +0100 |
| commit | 5466f96bd75f602f5b5fd44a7ccee745f2abfca0 (patch) | |
| tree | 52370ece205756f31dce32ddd607d1884ad1e2a0 /recourses/Buzzer.py | |
| parent | 6198d0333d432b4e0dad7e8da2c2395473a12995 (diff) | |
no clue what i did here
Diffstat (limited to 'recourses/Buzzer.py')
| -rw-r--r-- | recourses/Buzzer.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/recourses/Buzzer.py b/recourses/Buzzer.py new file mode 100644 index 0000000..8555184 --- /dev/null +++ b/recourses/Buzzer.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python
+
+import RPi.GPIO as GPIO
+import time
+
+# Set #17 as buzzer pin
+BeepPin = 17
+
+def print_message():
+ print("========================================")
+ print ("| Beep |")
+ print ("| ------------------------------ |")
+ print ("| Buzzer connect to GPIO0 |")
+ print ("| |")
+ print ("| Make Buzzer beep |")
+ print ("| |")
+ print ("| |")
+ print ("========================================\n")
+ print 'Program is running...'
+ print 'Please press Ctrl+C to end the program...'
+ raw_input ("Press Enter to begin\n")
+
+def setup():
+ # Set the GPIO modes to BCM Numbering
+ GPIO.setmode(GPIO.BCM)
+ # Set LedPin's mode to output,
+ # and initial level to High(3.3v)
+ GPIO.setup(BeepPin, GPIO.OUT, initial=GPIO.HIGH)
+
+def main():
+ print_message()
+ while True:
+ # Buzzer on (Beep)
+ print 'Buzzer On'
+ GPIO.output(BeepPin, GPIO.LOW)
+ time.sleep(0.1)
+ # Buzzer off
+ print 'Buzzer Off'
+ GPIO.output(BeepPin, GPIO.HIGH)
+ time.sleep(0.1)
+
+def destroy():
+ # Turn off buzzer
+ GPIO.output(BeepPin, GPIO.HIGH)
+ # Release resource
+ GPIO.cleanup()
+
+# If run this script directly, do:
+if __name__ == '__main__':
+ setup()
+ try:
+ main()
+ # When 'Ctrl+C' is pressed, the child program
+ # destroy() will be executed.
+ except KeyboardInterrupt:
+ destroy()
\ No newline at end of file |
