Example #1
0
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)

        for i in range(1):
            if (touchData & (1 << i)):

                if (touches[i] == 0):

                    print('Pin ' + str(i) + ' was just touched')

                    if (i == 0):
                        is_led_on = not is_led_on
                        GPIO.output(12, is_led_on)
                        time.sleep(.3)

                    #else:
                    #	GPIO.output(12,is_led_on)
Example #2
0
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
# Track the touches with this array. If a beet has been touched, the corresponding value in the array becomes 1
touches = [0,0,0,0,0,0];

while True:

	# IRQ is the Interrupt Request signal pin. It is pulled up to 3.3V on the breakout and when the sensor chip detects a change in the touch sense switches, 
	# the pin goes to 0V until the data is read over i2c.

	# This if checks if the interupt pin has a high signal. if so, break the loop.
	if (GPIO.input(7)): # If the GPIO's pin 7 (Interupt) is high
		pass
 
	else: # Interupt pin is low

		# Reads data from mpr121 through default address value of 0x5a.
		touchData = mpr121.readData(0x5a)
		
		# Simultaneously loop through each beet and check if it is touched.
		for i in range(6):
			#*give information about bitwise manipulation
			if (touchData & (1<<i)):

				# If the beet i is not currently touched and is touched, print the beet that was touched, and play the corresponding wav file.
				if (touches[i] == 0):

					''' ADD A PRINT STATEMENT TO OUTPUT WHICH PIN WAS TOUCHED '''
					# print( 'Pin ' + str(i) + ' was just touched')

					''' USE PYGAME .PLAY() METHOD TO PLAY EACH SOUND BASED ON PIN (i VALUE) TOUCHED'''
					# if (i == 0):
					# 	kick.play()
Example #4
0
drumKit.append(closedhh)
drumKit.append(clap)
drumKit.append(cymbal)

# Track touches
touches = [0,0,0,0,0,0];

#Run main loop
while True:
	try:

		#Detect input
		if (GPIO.input(7)): # Interupt pin is high
			pass
		else: # Interupt pin is low
			touchData = mpr121.readData(0x5a) #Take data from SDA Line
			for i in range(6): #Checks each touch value
				if (touchData & (1<<i)):
					if (touches[i] == 0):
						print( 'Pin ' + str(i) + ' was just touched') #Track changes, can be commented out
						drumKit[i].play()	

						#if (i == 0):
						#	kick.play()
						#elif (i == 1):
						#	snare.play()
						#elif (i == 2):
						#	openhh.play()
						#elif (i == 3):
						#	closedhh.play()
						#elif (i == 4):