Пример #1
0
 def testWaitForRising(self):
     def makehigh():
         GPIO.output(LOOP_OUT, GPIO.HIGH)
     GPIO.output(LOOP_OUT, GPIO.LOW)
     t = Timer(0.1, makehigh)
     t.start()
     GPIO.wait_for_edge(LOOP_IN, GPIO.RISING)
Пример #2
0
 def testWaitForFalling(self):
     def makelow():
         GPIO.output(LOOP_OUT, GPIO.LOW)
     GPIO.output(LOOP_OUT, GPIO.HIGH)
     t = Timer(0.1, makelow)
     t.start()
     GPIO.wait_for_edge(LOOP_IN, GPIO.FALLING)
Пример #3
0
 def test_switchbounce(self):
     self.switchcount = 0
     print "\nSwitch bounce test.  Press switch at least 10 times and count..."
     GPIO.add_event_detect(SWITCH_PIN, GPIO.FALLING, callback=self.cb, bouncetime=200)
     while self.switchcount < 10:
         time.sleep(1)
     GPIO.remove_event_detect(SWITCH_PIN)
Пример #4
0
 def test_loopback(self):
     """Test output loops back to another input"""
     GPIO.setup(LOOP_IN, GPIO.IN, pull_up_down=GPIO.PUD_OFF)
     GPIO.setup(LOOP_OUT, GPIO.OUT, initial=GPIO.LOW)
     self.assertEqual(GPIO.input(LOOP_IN), GPIO.LOW)
     GPIO.output(LOOP_OUT, GPIO.HIGH)
     self.assertEqual(GPIO.input(LOOP_IN), GPIO.HIGH)
     GPIO.cleanup()
Пример #5
0
 def test_outputread(self):
     """Test that an output() can be input()"""
     GPIO.setup(LED_PIN, GPIO.OUT)
     GPIO.output(LED_PIN, GPIO.HIGH)
     self.assertEqual(GPIO.input(LED_PIN), GPIO.HIGH)
     GPIO.output(LED_PIN, GPIO.LOW)
     self.assertEqual(GPIO.input(LED_PIN), GPIO.LOW)
     GPIO.cleanup()
Пример #6
0
 def test_cleanall(self):
     GPIO.setup(LOOP_OUT, GPIO.OUT)
     GPIO.setup(LED_PIN, GPIO.OUT)
     self.assertEqual(GPIO.gpio_function(LOOP_OUT), GPIO.OUT)
     self.assertEqual(GPIO.gpio_function(LED_PIN), GPIO.OUT)
     GPIO.cleanup()
     self.assertEqual(GPIO.gpio_function(LOOP_OUT), GPIO.IN)
     self.assertEqual(GPIO.gpio_function(LED_PIN), GPIO.IN)
Пример #7
0
 def test_event_detected(self):
     self.switchcount = 0
     print "\nGPIO.event_detected() switch bounce test.  Press switch at least 10 times and count..."
     GPIO.add_event_detect(SWITCH_PIN, GPIO.FALLING, bouncetime=200)
     while self.switchcount < 10:
         if GPIO.event_detected(SWITCH_PIN):
             self.switchcount += 1
             print 'Button press',self.switchcount
     GPIO.remove_event_detect(SWITCH_PIN)
Пример #8
0
	def reset(self):
		GPIO.output(self.pin1,GPIO.LOW)
		GPIO.output(self.pin2,GPIO.LOW)
		GPIO.output(self.pin3,GPIO.LOW)
		GPIO.output(self.pin4,GPIO.LOW)
		self.moving = False
		return	
Пример #9
0
	def lock(self):
		GPIO.output(self.pin1,GPIO.HIGH)
		GPIO.output(self.pin2,GPIO.LOW)
		GPIO.output(self.pin3,GPIO.LOW)
		GPIO.output(self.pin4,GPIO.HIGH)
		self.moving = False
		return	
Пример #10
0
def handler(signum, frame):
    SPIsend(SPI_SLAVE_ADDR, SPI_IOCONA, 0x00)
    SPIsend(SPI_SLAVE_ADDR, SPI_IOCONB, 0x00)
    SPIsend(SPI_SLAVE_ADDR, SPI_GPIOA, 0x00)
    GPIO.cleanup()
    os.system("clear")
    print("Clean")
    if Failed == 0:
        PSent = "Sent: {0}".format(Sent)
        PRecv = " | Received: {0}".format(Finished)
        PFail = " | Failed: {0}".format(Failed)
        PPerc = " | Failure: 0%"
    else:
        PSent = "Sent: {0}".format(Sent)
        PRecv = " | Received: {0}".format(Finished)
        PFail = " | Failed: {0}".format(Failed)
        PPerc = " | Failure: {0}%".format(str(100 / (Sent / Failed)))
    print(PSent + PRecv + PFail)
    sys.exit()
Пример #11
0
def testEventDetect(pin, trigger):
	switchCnt = 0	
	GPIO.setup(pin, GPIO.IN, GPIO.PUD_UP)

	GPIO.add_event_detect(pin, trigger)

	while switchCnt < 2:   
		if GPIO.event_detected(pin):
			switchCnt += 1
			print 'The event has been detected'
			print "\n value_%d = %d\n" %(pin,GPIO.input(pin))

	GPIO.remove_event_detect(pin)
Пример #12
0
 def testExceptionInCallback(self):
     self.run_cb = False
     def cb(channel):
         with self.assertRaises(ZeroDivisionError):
             self.run_cb = True
             a = 1/0
     GPIO.output(LOOP_OUT, GPIO.LOW)
     GPIO.add_event_detect(LOOP_IN, GPIO.RISING, callback=cb)
     time.sleep(0.001)
     GPIO.output(LOOP_OUT, GPIO.HIGH)
     time.sleep(0.001)
     self.assertEqual(self.run_cb, True)
     GPIO.remove_event_detect(LOOP_IN)
Пример #13
0
def SPIsend(opcode, addr, data):
    GPIO.setup(SPI_CS0, GPIO.OUT)
    GPIO.output(SPI_CS0, GPIO.LOW)
    SPIsendValue(opcode | SPI_SLAVE_WRITE)
    SPIsendValue(addr)
    SPIsendValue(data)
    GPIO.output(SPI_CS0, GPIO.HIGH)
Пример #14
0
 def runTest(self):
     GPIO.setup(LED_PIN, GPIO.OUT)
     pwm = GPIO.PWM(LED_PIN, 50)
     pwm.start(100)
     print "\nPWM tests"
     response = raw_input('Is the LED on (y/n) ? ').upper()
     self.assertEqual(response,'Y')
     pwm.start(0)
     response = raw_input('Is the LED off (y/n) ? ').upper()
     self.assertEqual(response,'Y')
     print "LED Brighten/fade test..."
     for i in range(0,3):
         for x in range(0,101,5):
             pwm.ChangeDutyCycle(x)
             time.sleep(0.1)
         for x in range(100,-1,-5):
             pwm.ChangeDutyCycle(x)
             time.sleep(0.1)
     pwm.stop()
     response = raw_input('Did it work (y/n) ? ').upper()
     self.assertEqual(response,'Y')
     GPIO.cleanup()
Пример #15
0
def testPwm(mode, pins):
	if mode == "BOARD":
		print "Start to test the mode: %s" %(mode)
		GPIO.setmode(GPIO.BOARD)
	elif mode == "BCM":
		print "Start to test the mode: %s" %(mode)
		GPIO.setmode(GPIO.BCM)
	else:
		print "Invalid test mode: %s" %(mode)

	for i in pins: 
		GPIO.setup(i,GPIO.OUT)
		p = GPIO.PWM(i,100)   #set freq: 100HZ
		p.start(10)           #duty cycle: 10%
		time.sleep(1)
		
		p.start(100)          #duty cycle: 100%
		time.sleep(1)

		GPIO.output(i, False)		
		p.stop()

	GPIO.cleanup()
Пример #16
0
'''
We use the program to test input of the pins
'''
import LMK.GPIO as GPIO
import time

#----------P3  P5  P7  P8  P10  P11  P12  P13  P15  P16  P18  P19 P21  P22  P23  P24 P26 P27 P28 P29  P31  P32  P33  P35  P36  P37  P38  P40-----------#
phyPins = (3,  5,  7,  8,  10,  11,  12,  13,  15,  16,  18,  19, 21,  22,  23,  24, 26, 27, 28, 29,  31,  32,  33,  35,  36,  37,  38,  40)
bcmPins = (2,  3,  4,  14, 15,  17,  18,  27,  22,  23,  24,  10,  9,  25,  11,  8,   7,  0,  1,  5,  6,   12,  13,  19,  16,  26,  20,  21)

pinOut = 3
pinIn  = 5

GPIO.setmode(GPIO.BOARD)
GPIO.setup(pinOut,GPIO.OUT)
GPIO.setup(pinIn,GPIO.IN)

while True:
	GPIO.output(pinOut,True)
	print "value = %d\n" %(GPIO.input(pinIn)) 
	time.sleep(1)
	GPIO.output(pinOut,False)
	print "value = %d\n" %(GPIO.input(pinIn))
	time.sleep(1)

GPIO.cleanup()
Пример #17
0
	def init(self):
		GPIO.setmode(GPIO.BCM)
		GPIO.setwarnings(False)
		GPIO.setup(self.pin1,GPIO.OUT)
		GPIO.setup(self.pin2,GPIO.OUT)
		GPIO.setup(self.pin3,GPIO.OUT)
		GPIO.setup(self.pin4,GPIO.OUT)
		self.zeroPosition()
		return	
Пример #18
0
def testOutput(mode, pins):
	if mode == "BOARD":
		print "Start to test the mode: %s" %(mode)
		GPIO.setmode(GPIO.BOARD)
	elif mode == "BCM":
		print "Start to test the mode: %s" %(mode)
		GPIO.setmode(GPIO.BCM)
	else:
		print "Invalid test mode: %s" %(mode)

	for i in pins:
		try:
			GPIO.setup(i, GPIO.OUT)
		except:
			print("Failed to setup GPIO %d", i)
			continue

		GPIO.output(i, True)
		time.sleep(0.5)
		GPIO.output(i, False)
		time.sleep(0.5)

	GPIO.cleanup()
Пример #19
0
#!/usr/bin/env python
import LMK.GPIO as GPIO
import time
PIN_0 = 3
PIN_1 = 5
#GPIO.setmode(GPIO.BCM)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIN_0,GPIO.OUT)
GPIO.setup(PIN_1,GPIO.IN)

while True:
	GPIO.output(PIN_0,True)
	print "\n value = %d\n" %(GPIO.input(PIN_1))	
	time.sleep(1)
	GPIO.output(PIN_0,False)
	print "\n value = %d\n" %(GPIO.input(PIN_1))
	time.sleep(1)

GPIO.cleanup()
Пример #20
0
import LMK.GPIO as GPIO
import time

#The following pins support the external event detected on the 40Pin Header of the LeMake Guitar
'''P8 P10 P12 P13 P15 P16 P22 P19 P23'''

#The following pins support the external event detected on the 40Pin Header of the BananaPro
'''P7 P8 P10 P11 P13 P15 P16 P18 P19 P21 P22 P23 P24 P26'''

testPinOnGt = 8   #For LeMaker Guitar
testPinonBP = 18  #For BananaPro

GPIO.setmode(GPIO.BOARD)
GPIO.setup(testPinOnGt, GPIO.IN, GPIO.PUD_UP)
if None == GPIO.wait_for_edge(testPinOnGt, GPIO.RISING):
	print "specified edge detected"

GPIO.cleanup()
Пример #21
0
'''
We use the program to test the output of the pins
'''
import LMK.GPIO as GPIO
import time

#----------P3  P5  P7  P8  P10  P11  P12  P13  P15  P16  P18  P19 P21  P22  P23  P24 P26 P27 P28 P29  P31  P32  P33  P35  P36  P37  P38  P40-----------#
phyPins = (3,  5,  7,  8,  10,  11,  12,  13,  15,  16,  18,  19, 21,  22,  23,  24, 26, 27, 28, 29,  31,  32,  33,  35,  36,  37,  38,  40)
bcmPins = (2,  3,  4,  14, 15,  17,  18,  27,  22,  23,  24,  10,  9,  25,  11,  8,   7,  0,  1,  5,  6,   12,  13,  19,  16,  26,  20,  21)

GPIO.setmode(GPIO.BOARD)

def testOutput(mode, pins):
	if mode == "BOARD":
		print "Start to test the mode: %s" %(mode)
		GPIO.setmode(GPIO.BOARD)
	elif mode == "BCM":
		print "Start to test the mode: %s" %(mode)
		GPIO.setmode(GPIO.BCM)
	else:
		print "Invalid test mode: %s" %(mode)

	for i in pins:
		try:
			GPIO.setup(i, GPIO.OUT)
		except:
			print("Failed to setup GPIO %d", i)
			continue

		GPIO.output(i, True)
		time.sleep(0.5)
Пример #22
0
def testPwm(mode, pins):
    if mode == "BOARD":
        print "Start to test the mode: %s" % (mode)
        GPIO.setmode(GPIO.BOARD)
    elif mode == "BCM":
        print "Start to test the mode: %s" % (mode)
        GPIO.setmode(GPIO.BCM)
    else:
        print "Invalid test mode: %s" % (mode)

    for i in pins:
        GPIO.setup(i, GPIO.OUT)
        p = GPIO.PWM(i, 100)  #set freq: 100HZ
        p.start(10)  #duty cycle: 10%
        time.sleep(1)

        p.start(100)  #duty cycle: 100%
        time.sleep(1)

        GPIO.output(i, False)
        p.stop()

    GPIO.cleanup()
Пример #23
0
#!/usr/bin/env python
import LMK.GPIO as GPIO
import time
LED_PIN = 12

GPIO.setmode(GPIO.BOARD)
GPIO.setup(LED_PIN,GPIO.OUT)
pwm = GPIO.PWM(LED_PIN, 50)
pwm.start(100)
print "\nPWM tests"
response = raw_input('Is the LED on (y/n) ? ').upper()
self.assertEqual(response,'Y')
pwm.start(0)
response = raw_input('Is the LED off (y/n) ? ').upper()
self.assertEqual(response,'Y')

print "LED Brighten/fade test..."
for i in range(0,3):
	for x in range(0,101,5):
		pwm.ChangeDutyCycle(x)
		time.sleep(0.1)
	for x in range(100,-1,-5):
		pwm.ChangeDutyCycle(x)
		time.sleep(0.1)
pwm.stop()
response = raw_input('Did it work (y/n) ? ').upper()
self.assertEqual(response,'Y')
GPIO.cleanup()

import LMK.GPIO as GPIO 
import time

#PIN_NUM = 24
#GPIO.setmode(GPIO.BOARD)
#GPIO.setup(PIN_NUM,GPIO.IN,GPIO.PUD_DOWN)

GPIO.setmode(GPIO.RAW)
GPIO.setup(GPIO.PI+10,GPIO.IN,GPIO.PUD_DOWN)

print "The value of Pin %d is %d" %(GPIO.PI+10,GPIO.input(GPIO.PI+10))


def my_callback(channel):
	print "Callback trigger %d" %channel
	print "Now value of the Pin is %d" %(GPIO.input(GPIO.PI+10))
	print "Click Ctr + C to exit"

GPIO.add_event_detect(GPIO.PI+10,GPIO.RISING,callback = my_callback,bouncetime = 300)

try:
    while True:
	time.sleep(0.1)
except KeyboardInterrupt:
    pass

GPIO.cleanup()

def my_callback(channel):
	print "Callback trigger %d" %channel
	print "Now value of the Pin is %d" %(GPIO.input(GPIO.PI+10))
	print "Click Ctr + C to exit"
Пример #26
0
#!/usr/bin/env python
import LMK.GPIO as GPIO
import time
PIN_NUM = 7
PIN_IN = 10
val = 0
GPIO.setmode(GPIO.BOARD)
while 1:
    try:
        GPIO.setup(PIN_NUM, GPIO.OUT)
        GPIO.setup(PIN_IN, GPIO.IN)
    except:
        print("fail to setup GPIO %d", PIN_NUM)
    val = GPIO.input(PIN_IN)
    if val:
        GPIO.output(PIN_NUM, True)
    else:
        GPIO.output(PIN_NUM, False)
Пример #27
0
#pull-up/down pins for the LeMaker Guitar, and the P3, P5, P19 and P23 of the pull-up has been enabled by
#connecting the external pull-up resistor, don't need to operate by using the software.

#-----------P8 P10 P12 P13 P15 P16 P22-----------#
pullUpGt = (8, 10, 12, 13, 15, 16, 22
            )  #Pull-UP pins which be configured by the software
pullDwGt = (16, )  #Pull-Down pins which be configured by the software

#pull-up/down pins for the BananaPro, and the P3, P5, P27 and P28 of the pull-up have been enabled by
#connecting the external pull-up resistor, don't need to operate by using the software.

#-----------P7  P8  P10  P11  P12  P13  P15  P16  P18  P19 P21  P22  P23  P24 P26 P29  P31  P32  P33  P35  P36  P37  P38  P40-----------#
pullUpBP = (7, 8, 10, 11, 12, 13, 15, 16, 18, 19, 21, 22, 23, 24, 26, 29, 31,
            32, 33, 35, 36, 37, 38, 40)
PullDwBP = (7, 8, 10, 11, 12, 13, 15, 16, 18, 19, 21, 22, 23, 24, 26, 29, 31,
            32, 33, 35, 36, 37, 38, 40)

#GPIO.PUD_UP    #enable pull-up
#GPIO.PUD_DOWN  #enable pull-down
#GPIO.PUD_OFF   #disable pull-up/down

GPIO.setmode(GPIO.BOARD)
for i in pullUpGt:
    GPIO.setup(i, GPIO.IN, pull_up_down=GPIO.PUD_UP)  #enable pull-up
    time.sleep(1)
    GPIO.setup(i, GPIO.IN, pull_up_down=GPIO.PUD_OFF)  #disable pull-up
    time.sleep(0)

GPIO.cleanup()
Пример #28
0
#/usr/bin/env python

import LMK.GPIO as GPIO
import time

PIN_NUM = 11

GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIN_NUM,GPIO.OUT)

p = GPIO.PWM(PIN_NUM,0.5)
p.start(50)
raw_input("Press Enter to stop:")
p.stop()
GPIO.cleanup()
Пример #29
0
#!/usr/bin/env python
import LMK.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_UP)
print "\n value_7 = %d\n" %(GPIO.input(7))	

GPIO.setup(8, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
print "\n value_8 = %d\n" %(GPIO.input(8))	

GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP)
print "\n value_12 = %d\n" %(GPIO.input(12))	
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
print "\n value_12 = %d\n" %(GPIO.input(12))	

#GPIO.cleanup()
Пример #30
0
import LMK.GPIO as GPIO
import time

#The following pins support the external event detected on the 40Pin Header of the LeMake Guitar
'''P8 P10 P12 P13 P15 P16 P22 P19 P23'''

#The following pins support the external event detected on the 40Pin Header of the BananaPro
'''P7 P8 P10 P11 P13 P15 P16 P18 P19 P21 P22 P23 P24 P26'''

testPinOnGt = 8  #For LeMaker Guitar
testPinonBP = 18  #For BananaPro

GPIO.setmode(GPIO.BOARD)
GPIO.setup(testPinOnGt, GPIO.IN, GPIO.PUD_UP)
if None == GPIO.wait_for_edge(testPinOnGt, GPIO.RISING):
    print "specified edge detected"

GPIO.cleanup()
Пример #31
0
	def turn(self,steps,direction):
		global CLOCKWISE
		self.stop()
		self.moving = True
		self.steps = steps		
		mrange = len(out1)
		while self.steps > 0:
			if direction == self.CLOCKWISE:
				for pin in range(mrange):
					GPIO.output(self.pin1,out1[pin])
					GPIO.output(self.pin2,out2[pin])
					GPIO.output(self.pin3,out3[pin])
					GPIO.output(self.pin4,out4[pin])
					time.sleep(self.speed)
				self.incrementPosition()
			else:
				for pin in reversed(range(mrange)):
					GPIO.output(self.pin1,out1[pin])
					GPIO.output(self.pin2,out2[pin])
					GPIO.output(self.pin3,out3[pin])
					GPIO.output(self.pin4,out4[pin])
					time.sleep(self.speed)
				self.decrementPosition()
			self.steps -= 1
			if self.halt:
				break
		self.stop()
		return
Пример #32
0
#!/usr/bin/env python
import LMK.GPIO as GPIO
import time
from threading import Timer

SWITCH_PIN = 18
GPIO.setmode(GPIO.BOARD)
GPIO.setup(SWITCH_PIN,GPIO.IN,GPIO.PUD_UP)
print "\n value_%d = %d\n" %(SWITCH_PIN,GPIO.input(SWITCH_PIN))

GPIO.add_event_detect(SWITCH_PIN, GPIO.RISING,bouncetime=200)  # add rising edge detection on a channel

switchcount = 0
while switchcount < 2:   
	if GPIO.event_detected(SWITCH_PIN):
		switchcount += 1
		print 'Button pressed',switchcount
		print "\n value_%d = %d\n" %(SWITCH_PIN,GPIO.input(SWITCH_PIN))
		

GPIO.remove_event_detect(SWITCH_PIN)
Пример #33
0
'''
We use the program to detect the pin function, eg: input, output
'''
import LMK.GPIO as GPIO

#----------P3  P5  P7  P8  P10  P11  P12  P13  P15  P16  P18  P19 P21  P22  P23  P24 P26 P27 P28 P29  P31  P32  P33  P35  P36  P37  P38  P40-----------#
phy_pins = (3, 5, 7, 8, 10, 11, 12, 13, 15, 16, 18, 19, 21, 22, 23, 24, 26, 27,
            28, 29, 31, 32, 33, 35, 36, 37, 38, 40)
bcm_pins = (2, 3, 4, 14, 15, 17, 18, 27, 22, 23, 24, 10, 9, 25, 11, 8, 7, 0, 1,
            5, 6, 12, 13, 19, 16, 26, 20, 21)

validPins = (11, 12, 13, 15)

GPIO.setmode(GPIO.BOARD)

GPIO.setup(11, GPIO.IN)
GPIO.setup(12, GPIO.OUT)
GPIO.setup(13, GPIO.IN)
GPIO.setup(15, GPIO.OUT)

for pin in validPins:
    ret = GPIO.gpio_function(pin)
    print ret

GPIO.cleanup()
Пример #34
0
'''
We use the program to detect the pin function, eg: input, output
'''
import LMK.GPIO as GPIO

#----------P3  P5  P7  P8  P10  P11  P12  P13  P15  P16  P18  P19 P21  P22  P23  P24 P26 P27 P28 P29  P31  P32  P33  P35  P36  P37  P38  P40-----------#
phy_pins = (3,  5,  7,  8,  10,  11,  12,  13,  15,  16,  18,  19, 21,  22,  23,  24, 26, 27, 28, 29,  31,  32,  33,  35,  36,  37,  38,  40)
bcm_pins = (2,  3,  4,  14, 15,  17,  18,  27,  22,  23,  24,  10,  9,  25,  11,  8,   7,  0,  1,  5,  6,   12,  13,  19,  16,  26,  20,  21)

validPins = (11,12,13,15)

GPIO.setmode(GPIO.BOARD)

GPIO.setup(11,GPIO.IN)
GPIO.setup(12,GPIO.OUT)
GPIO.setup(13,GPIO.IN)
GPIO.setup(15,GPIO.OUT)

for pin in validPins:
	ret = GPIO.gpio_function(pin)
	print ret

GPIO.cleanup()
Пример #35
0
import LMK.GPIO as GPIO
import time

#The following pins support the external event detected on the 40Pin Header of the LeMake Guitar
'''P8 P10 P12 P13 P15 P16 P22 P19 P23'''

#The following pins support the external event detected on the 40Pin Header of the BananaPro
'''P7 P8 P10 P11 P13 P15 P16 P18 P19 P21 P22 P23 P24 P26'''

testPinOnGt = 8   #For LeMaker Guitar
testPinonBP = 18  #For BananaPro

GPIO.setmode(GPIO.BOARD)

def testEventDetect(pin, trigger):
	switchCnt = 0	
	GPIO.setup(pin, GPIO.IN, GPIO.PUD_UP)

	GPIO.add_event_detect(pin, trigger)

	while switchCnt < 2:   
		if GPIO.event_detected(pin):
			switchCnt += 1
			print 'The event has been detected'
			print "\n value_%d = %d\n" %(pin,GPIO.input(pin))

	GPIO.remove_event_detect(pin)

testEventDetect(testPinOnGt, GPIO.RISING)  # add rising edge detection on a channel

GPIO.cleanup()
Пример #36
0
import LMK.GPIO as GPIO
import time

#The following pins support the external event detected on the 40Pin Header of the LeMake Guitar
'''P8 P10 P12 P13 P15 P16 P22 P19 P23'''

#The following pins support the external event detected on the 40Pin Header of the BananaPro
'''P7 P8 P10 P11 P13 P15 P16 P18 P19 P21 P22 P23 P24 P26'''

testPinOnGt = 8  #For LeMaker Guitar
testPinOnBP = 18  #For BananaPro

GPIO.setmode(GPIO.BOARD)
GPIO.setup(testPinOnGt, GPIO.IN, GPIO.PUD_UP)


def testCallback(channel):
    print "running callback function", channel


GPIO.add_event_detect(testPinOnGt,
                      GPIO.RISING,
                      callback=testCallback,
                      bouncetime=300)

try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    pass
Пример #37
0
'''
import LMK.GPIO as GPIO
import time

#pull-up/down pins for the LeMaker Guitar, and the P3, P5, P19 and P23 of the pull-up has been enabled by 
#connecting the external pull-up resistor, don't need to operate by using the software.

#-----------P8 P10 P12 P13 P15 P16 P22-----------#
pullUpGt = (8, 10, 12, 13, 15, 16, 22)  #Pull-UP pins which be configured by the software
pullDwGt = (16,)                        #Pull-Down pins which be configured by the software

#pull-up/down pins for the BananaPro, and the P3, P5, P27 and P28 of the pull-up have been enabled by
#connecting the external pull-up resistor, don't need to operate by using the software.

#-----------P7  P8  P10  P11  P12  P13  P15  P16  P18  P19 P21  P22  P23  P24 P26 P29  P31  P32  P33  P35  P36  P37  P38  P40-----------#
pullUpBP = (7,  8,  10,  11,  12,  13,  15,  16,  18,  19, 21,  22,  23,  24, 26, 29,  31,  32,  33,  35,  36,  37,  38,  40)
PullDwBP = (7,  8,  10,  11,  12,  13,  15,  16,  18,  19, 21,  22,  23,  24, 26, 29,  31,  32,  33,  35,  36,  37,  38,  40)

#GPIO.PUD_UP    #enable pull-up
#GPIO.PUD_DOWN  #enable pull-down
#GPIO.PUD_OFF   #disable pull-up/down

GPIO.setmode(GPIO.BOARD)
for i in pullUpGt:
	GPIO.setup(i, GPIO.IN, pull_up_down=GPIO.PUD_UP)  #enable pull-up
	time.sleep(1)  
	GPIO.setup(i, GPIO.IN, pull_up_down=GPIO.PUD_OFF) #disable pull-up
	time.sleep(0)

GPIO.cleanup()
Пример #38
0
'''
We use the program to test variation of duty cycle, and observe the brightness of the leds after running the program.
'''
import LMK.GPIO as GPIO
import time

#----------P3  P5  P7  P8  P10  P11  P12  P13  P15  P16  P18  P19 P21  P22  P23  P24 P26 P27 P28 P29  P31  P32  P33  P35  P36  P37  P38  P40-----------#
phyPins = (3,  5,  7,  8,  10,  11,  12,  13,  15,  16,  18,  19, 21,  22,  23,  24, 26, 27, 28, 29,  31,  32,  33,  35,  36,  37,  38,  40)
bcmPins = (2,  3,  4,  14, 15,  17,  18,  27,  22,  23,  24,  10,  9,  25,  11,  8,   7,  0,  1,  5,  6,   12,  13,  19,  16,  26,  20,  21)

pinNum = 12
frequency = 100  #100HZ

GPIO.setmode(GPIO.BOARD)
GPIO.setup(pinNum,GPIO.OUT)

p = GPIO.PWM(pinNum,frequency)
p.start(0)
try:
    while True:
        for dutyCycle in range(0,100,5):
            p.ChangeDutyCycle(dutyCycle)
            time.sleep(0.1)
        for dutyCycle in range(100,0,-5):
            p.ChangeDutyCycle(dutyCycle)
            time.sleep(0.1)
except KeyboardInterrupt:
    pass

p.stop()