def __init__(self): self.pir = MyPiPIR(MyPiPIR.DEFAULT) self.led = MyPiLed(MyPiLed.RED) self.buzzer = MyPiBuzzer(MyPiBuzzer.DEFAULT) self.locks = [] self.tries = 0 self.max_tries = 3 self.locks.append(Lock('Vault')) self.logger = MyLogger("SecuritySystem") self.check_interval = self.__class__.CHECK_INTERVAL self.enabled = False
#!/usr/bin/python # Get LED control class import RPi.GPIO as GPIO from led import MyPiLed try: yellow = MyPiLed(MyPiLed.YELLOW) red = MyPiLed(MyPiLed.RED) # Blink LEDs yellow.blink(4, 0.5) red.blink(5, 0.8) except KeyboardInterrupt: print("Quit!") finally: GPIO.cleanup()
from led import MyPiLed from my_queue import MyQueue import os try: yellow = MyPiLed(4) red = MyPiLed(17) q = MyQueue() count = 0 led_choice = 0 os.system("clear") print("Which LED do you want to flash?") print("1: Yellow?") print("2: Red?") led_choice = input("Choose your option: ") os.system("clear") if led_choice == '1': print("You picked the Yellow LED") count = input("How many times do you want to blink?: ") yellow.blink(int(count), 0.5) if led_choice == '2': print("You picked the Red LED") count = input("How many times do you want to blink?: ") red.blink(int(count), 0.5) except:
from led import MyPiLed led1 = MyPiLed(MyPiLed.RED) led2 = MyPiLed(MyPiLed.YELLOW) print("Non blocking") threads = [] threads.append(led1.blink(20, 0.5)) threads.append(led2.blink(30, 0.2)) for t in threads: t.join() print("Blocking") led1.blink(5, 0.5, True) led2.blink(5, 0.5, True)
import time import RPi.GPIO as GPIO from pir import MyPiPIR from led import MyPiLed from buzzer import MyPiBuzzer from my_logger import MyLogger logger = MyLogger("PIR") logger.debug("PIR Module Test (Ctrl-C to exit)") pir1 = MyPiPIR(MyPiPIR.DEFAULT) led1 = MyPiLed(MyPiLed.RED) buzzer1 = MyPiBuzzer(MyPiBuzzer.DEFAULT) check_interval = 0.01 try: logger.info("Ready!") while True: state = pir1.state() if state == MyPiPIR.ACTIVATED: logger.warn("Motion detected!") buzzer1.on() led1.blink(5, 0.2) time.sleep(1) elif state == MyPiPIR.DEACTIVATED: logger.info("Waiting for motion...") led1.off() buzzer1.off()