本文整理汇总了Python中LMK.GPIO.setup方法的典型用法代码示例。如果您正苦于以下问题:Python GPIO.setup方法的具体用法?Python GPIO.setup怎么用?Python GPIO.setup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LMK.GPIO
的用法示例。
在下文中一共展示了GPIO.setup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SPIsend
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import setup [as 别名]
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)
示例2: test_alreadyinuse
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import setup [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()
示例3: test_loopback
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import setup [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()
示例4: test_outputread
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import setup [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()
示例5: test_cleanall
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import setup [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)
示例6: SPIsendValue
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import setup [as 别名]
def SPIsendValue(value):
GPIO.setup(SPI_MOSI, GPIO.OUT)
GPIO.setup(SPI_SCLK, GPIO.OUT)
for i in range(8):
if (value & 0x80):
GPIO.output(SPI_MOSI, GPIO.HIGH)
else:
GPIO.output(SPI_MOSI, GPIO.LOW)
GPIO.output(SPI_SCLK, GPIO.HIGH)
GPIO.output(SPI_SCLK, GPIO.LOW)
value <<= 1
示例7: testEventDetect
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import setup [as 别名]
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)
示例8: SPIread
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import setup [as 别名]
def SPIread(opcode, addr):
GPIO.setup(SPI_MISO, GPIO.IN)
GPIO.output(SPI_CS0, GPIO.LOW)
SPIsendValue(opcode | SPI_SLAVE_READ)
SPIsendValue(addr)
value = 0
for i in range(8):
value <<= 1
if(GPIO.input(SPI_MISO)):
value |= 0x01
GPIO.output(SPI_SCLK, GPIO.HIGH)
GPIO.output(SPI_SCLK, GPIO.LOW)
GPIO.output(SPI_CS0, GPIO.HIGH)
return value
示例9: init
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import setup [as 别名]
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
示例10: test_cleanupwarning
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import setup [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: runTest
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import setup [as 别名]
def runTest(self):
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED_PIN_BCM, GPIO.IN)
self.assertEqual(GPIO.gpio_function(LED_PIN_BCM), GPIO.IN)
GPIO.setup(LED_PIN_BCM, GPIO.OUT)
self.assertEqual(GPIO.gpio_function(LED_PIN_BCM), GPIO.OUT)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(LED_PIN, GPIO.IN)
self.assertEqual(GPIO.gpio_function(LED_PIN), GPIO.IN)
GPIO.setup(LED_PIN, GPIO.OUT)
self.assertEqual(GPIO.gpio_function(LED_PIN), GPIO.OUT)
示例12: calDistance
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import setup [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
示例13: testPwm
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import setup [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()
示例14: testOutput
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import setup [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()
示例15: LNdigital
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import setup [as 别名]
def LNdigital():
try:
GPIO.setup(SPI_SCLK, GPIO.OUT)
GPIO.setup(SPI_MOSI, GPIO.OUT)
GPIO.setup(SPI_MISO, GPIO.IN)
GPIO.setup(SPI_CS0, GPIO.OUT)
GPIO.output(SPI_CS0, GPIO.HIGH)
GPIO.output(SPI_SCLK, GPIO.LOW)
SPIsend(SPI_SLAVE_ADDR, SPI_IODIRA, 0x00)#outputs
SPIsend(SPI_SLAVE_ADDR, SPI_IODIRB, 0xFF)#inputs
SPIsend(SPI_SLAVE_ADDR, SPI_GPIOA, 0x00)
SPIsend(SPI_SLAVE_ADDR, SPI_GPIOB, 0xFF)
Test = SPIread(SPI_SLAVE_ADDR, SPI_GPIOA)
if Test == 0x00:
Addons["LNdigital"] = True
else:
Addons["LNdigital"] = False
except:
Addons["LNdigital"] = False