|
- #!/usr/bin/env python3
-
- from time import sleep
- import threading
-
- import aufgabe_b
-
- try:
- import RPi.GPIO as GPIO
- except RuntimeError:
- print("Error importing RPi.GPIO! Run this script as root.")
- exit(1)
-
- TASTER_PIN = 2
-
- def setup():
- # Run GPIO with PI pin numbers.
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(TASTER_PIN, GPIO.IN)
-
- def main():
- setup()
-
- # Pin, frequency in Hz
- led_thread1 = LED(17, 1000)
- led_thread1.run()
- led_thread2 = LED(18, 1000)
- led_thread2.run()
-
- # read taster
- try:
- while True:
- if GPIO.input(TASTER_PIN) == 1:
- print("Taster was pressed. Set new frequency.")
- led_thread1.new_random_frequency()
- led_thread2.new_random_frequency()
- except KeyboardInterrupt:
- GPIO.cleanup()
-
- if __name__ == "__main__":
- main()
|