本文整理汇总了Python中LMK.GPIO.cleanup方法的典型用法代码示例。如果您正苦于以下问题:Python GPIO.cleanup方法的具体用法?Python GPIO.cleanup怎么用?Python GPIO.cleanup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LMK.GPIO
的用法示例。
在下文中一共展示了GPIO.cleanup方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_alreadyinuse
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import cleanup [as 别名]
def test_alreadyinuse(self):
"""Test 'already in use' warning"""
GPIO.setwarnings(False)
with open('/sys/class/gpio/export','wb') as f:
f.write(str(LED_PIN_BCM).encode())
with open('/sys/class/gpio/gpio%s/direction'%LED_PIN_BCM,'wb') as f:
f.write(b'out')
with open('/sys/class/gpio/gpio%s/value'%LED_PIN_BCM,'wb') as f:
f.write(b'1')
with warnings.catch_warnings(record=True) as w:
GPIO.setup(LED_PIN, GPIO.OUT) # generate 'already in use' warning
self.assertEqual(len(w),0) # should be no warnings
with open('/sys/class/gpio/unexport','wb') as f:
f.write(str(LED_PIN_BCM).encode())
GPIO.cleanup()
GPIO.setwarnings(True)
with open('/sys/class/gpio/export','wb') as f:
f.write(str(LED_PIN_BCM).encode())
with open('/sys/class/gpio/gpio%s/direction'%LED_PIN_BCM,'wb') as f:
f.write(b'out')
with open('/sys/class/gpio/gpio%s/value'%LED_PIN_BCM,'wb') as f:
f.write(b'1')
with warnings.catch_warnings(record=True) as w:
GPIO.setup(LED_PIN, GPIO.OUT) # generate 'already in use' warning
self.assertEqual(w[0].category, RuntimeWarning)
with open('/sys/class/gpio/unexport','wb') as f:
f.write(str(LED_PIN_BCM).encode())
GPIO.cleanup()
示例2: test_loopback
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import cleanup [as 别名]
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()
示例3: test_outputread
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import cleanup [as 别名]
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()
示例4: test_cleanall
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import cleanup [as 别名]
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)
示例5: handler
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import cleanup [as 别名]
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()
示例6: runTest
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import cleanup [as 别名]
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()
示例7: testOutput
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import cleanup [as 别名]
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()
示例8: testPwm
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import cleanup [as 别名]
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()
示例9: calDistance
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import cleanup [as 别名]
def calDistance(trigger, echo):
stop = start = 0
GPIO.setup(trigger, GPIO.OUT)
GPIO.setup(echo, GPIO.IN)
GPIO.output(trigger, 0)
time.sleep(0.5)
GPIO.output(trigger, 1)
time.sleep(0.00001)
GPIO.output(trigger, 0)
start = time.time()
while GPIO.input(echo) == 0:
start = time.time()
while GPIO.input(echo) == 1:
stop = time.time()
delta = stop - start
print("UltraSonic time %.8f" % (delta))
distance = delta * 34300
distance = distance / 2.0
GPIO.cleanup()
return distance
示例10: test_cleanupwarning
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import cleanup [as 别名]
def test_cleanupwarning(self):
"""Test initial GPIO.cleanup() produces warning"""
GPIO.setwarnings(False)
GPIO.setup(SWITCH_PIN, GPIO.IN)
with warnings.catch_warnings(record=True) as w:
GPIO.cleanup()
self.assertEqual(len(w),0) # no warnings
GPIO.cleanup()
self.assertEqual(len(w),0) # no warnings
GPIO.setwarnings(True)
GPIO.setup(SWITCH_PIN, GPIO.IN)
with warnings.catch_warnings(record=True) as w:
GPIO.cleanup()
self.assertEqual(len(w),0) # no warnings
GPIO.cleanup()
self.assertEqual(w[0].category, RuntimeWarning) # a warning
示例11:
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import cleanup [as 别名]
'''
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()
示例12: test_output_on_input
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import cleanup [as 别名]
def test_output_on_input(self):
"""Test output() can not be done on input"""
GPIO.setup(SWITCH_PIN, GPIO.IN)
with self.assertRaises(RuntimeError):
GPIO.output(SWITCH_PIN, GPIO.LOW)
GPIO.cleanup()
示例13: tearDown
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import cleanup [as 别名]
def tearDown(self):
GPIO.cleanup()
示例14: range
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import cleanup [as 别名]
import LMK.GPIO as GPIO
import time
# channel = 15
GPIO.setmode(GPIO.RAW)
GPIO.setup(GPIO.PI + 17, GPIO.IN, GPIO.PUD_DOWN)
print " Now input is Low\n Our task is performed when it becomes High"
while True:
if GPIO.input(GPIO.PI + 17):
print "Input was High,begin to perform"
print "Count Down"
for i in range(7, 0, -1):
print "%d" % i
time.sleep(1)
print "Performed!"
exit()
GPIO.cleanup(GPIO.PI + 17)