def main(): #Create unix pipe main_pipe, fingerpint_pipe = Pipe() LCD_IN, LCD_OUT = Pipe() # Initializes LCD and LED LCD.init() LED.init() # Create an object of the class Parser and Poller parser = Parser() poller = Poller(parser, fingerpint_pipe, 1) # Create child process pid = os.fork() # Parent process if pid: try: # start the individual threads for LCD, NFC and poller lcd_thread = threading.Thread(target=LCD.new_start, args=(LCD_IN,)) lcd_thread.daeomon = True lcd_thread.start() nfc_thread = threading.Thread(target=nfcread.readNFC, args=(parser, fingerpint_pipe, LCD_OUT,)) nfc_thread.daeomon = True nfc_thread.start() poll_thread = threading.Thread(target=poller.startPolling) poll_thread.daeomon = True poll_thread.start() except: print "Error: unable to start thread" try: # Poll fingerprint pipe while 1: if fingerpint_pipe.poll(1): parser.course_id = fingerpint_pipe.recv() # Kill the threads and clears the LCD screen except KeyboardInterrupt: LCD.clear() os.kill(pid, signal.SIGKILL) os.kill(os.getpid(), signal.SIGKILL) sys.exit() else: # Start fingerprint on child procces try: fingerprint = Fingerprint() fingerprint.start(parser, main_pipe, LCD_OUT) # Clear the screen except KeyboardInterrupt: LCD.clear() sys.exit()
from led import LED import time import pygame if __name__ == "__main__": RED_PIN = 7 GREEN_PIN = 11 BLUE_PIN = 13 GPIO.setmode(GPIO.BOARD) bus = smbus.SMBus(1) # bus = smbus.SMBus(0) fuer Revision 1 address = 0x68 # via i2cdetect gy = Accel(bus, address) pygame.mixer.init() led = LED(RED_PIN, GREEN_PIN, BLUE_PIN) led.init() try: while True: x, y, z = gy.get_gyro() ax, ay, az = gy.get_accel() print("x: %f, y: %f, z: %f | ax: %f, ay: %f, az: %f" % (x, y, z, ax, ay, az)) time.sleep(1) # TODO: replace if statement with equivalent of "if sat on" if True: # play audio pygame.mixer.music.load("r2d2.wav") pygame.mixer.music.play() while pygame.mixer.music.get_busy() == True: