import RPi.GPIO as GPIO import mpr121 import time # Use GPIO Interrupt Pin GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.IN) GPIO.setup(12, GPIO.OUT) # Use mpr121 class for everything else mpr121.TOU_THRESH = 0x30 mpr121.REL_THRESH = 0x33 mpr121.setup(0x5a) # Track touches touches = [0] # initialize light is_led_on = False while True: if (GPIO.input(7)): # Interupt pin is high pass else: # Interupt pin is low touchData = mpr121.readData(0x5a)
import RPi.GPIO as GPIO import mpr121 import time import subprocess # Use GPIO Interrupt Pin GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.IN) # Use mpr121 class for everything else mpr121.TOU_THRESH = 0x30 mpr121.REL_THRESH = 0x33 mpr121.setup(0x5b) # User pygame for sounds # Track touches touches = [0,0,0,0,0,0,0,0,0,0,0,0]; # 1~# button use pass_pwd = [1,2,3,4]; # setting pwd pwd = [0,0,0,0]; # pwd temp input j = 0 # index key = 0 # strlen(pwd) => door open fail_work = 0 while True: if (GPIO.input(7)): # Interupt pin is high pass
bus = smbus.SMBus(1) address = 0x20 bus.write_byte_data(0x20, 0x00, 0x00) # Bank A as Outputs bus.write_byte_data(0x20, 0x01, 0x00) # Bank B as Outputs # Use GPIO Interrupt Pin GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.IN) # Use mpr121 class for everything else mpr121.TOU_THRESH = 0x10 mpr121.REL_THRESH = 0x13 mpr121.setup(0x5A) # User pygame for sounds pygame.mixer.pre_init(44100, -16, 12, 512) pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096) s1 = pygame.mixer.Sound("bird_caw2.wav") s1.set_volume(0.05) s2 = pygame.mixer.Sound("bird_chirp.wav") s2.set_volume(0.05) s3 = pygame.mixer.Sound("kick_01.wav") s3.set_volume(0.05) s4 = pygame.mixer.Sound("owl1.wav") s4.set_volume(0.05) s5 = pygame.mixer.Sound("peacock.wav")
import pygame import RPi.GPIO as GPIO import mpr121 # Use GPIO Interrupt Pin GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.IN) # Use mpr121 class for everything else mpr121.TOU_THRESH = 0x30 mpr121.REL_THRESH = 0x33 mpr121.setup(0x5a) # User pygame for sounds pygame.mixer.pre_init(44100, -16, 12, 512) ''' INITIALIZE PYGAME. SYNTAX IS IN PACKET ''' # pygame.init() ''' ADD 4 MORE SOUNDS USING FORMAT BELOW. LOOK THROUGH SAMPLES FOLDER AND PICK. ADD VOLUME AS APPROPRIATE ''' kick = pygame.mixer.Sound('samples/kick.wav') kick.set_volume(.65); snare = pygame.mixer.Sound('samples/snare.wav') snare.set_volume(.65);
def touch(): from multiprocessing import Process, Queue import RPi.GPIO as GPIO import mpr121 import time import subprocess import os global fail_work # Use GPIO Interrupt Pin GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.IN) # Use mpr121 class for everything else mpr121.TOU_THRESH = 0x30 mpr121.REL_THRESH = 0x33 mpr121.setup(0x5b) # User pygame for sounds # Track touches touches = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # 1~# button use pass_pwd = [1, 2, 3, 4] # setting pwd pwd = [0, 0, 0, 0] # pwd temp input j = 0 # index key = 0 # strlen(pwd) => door open fail_work = 0 while True: if (GPIO.input(7)): # Interupt pin is high pass else: # Interupt pin is low touchData = mpr121.readData(0x5b) for i in range(12): if (touchData & (1 << i)): if (touches[i] == 0): print('Pin ' + (str(i + 1)) + ' was just touched') time.sleep(0.3) touches[i] = 1 pwd[j] = (i + 1) if pass_pwd[j] == pwd[j]: key = key + 1 j = j + 1 if j == 4: j = 0 if key == 4: print "-------motor O" key = 0 else: print "-------motor X" key = 0 fail_work = fail_work + 1 #fail_call = "php putdata.php 2 "+"time " + str(fail_work) #print fail_call #print "fail : " + str(fail_work) t = open("time.txt", 'r') while True: line = t.readline() if not line: break fail_call = "php putdata.php 1 " + line + " " + str( fail_work) subprocess.call(fail_call, shell=True) print fail_call t.close() else: if (touches[i] == 1): print('Pin ' + str(i + 1) + ' was just released') time.sleep(0.3) touches[i] = 0 print pwd print key