本文整理汇总了Python中LMK.GPIO.output方法的典型用法代码示例。如果您正苦于以下问题:Python GPIO.output方法的具体用法?Python GPIO.output怎么用?Python GPIO.output使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LMK.GPIO
的用法示例。
在下文中一共展示了GPIO.output方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testWaitForFalling
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import output [as 别名]
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)
示例2: testWaitForRising
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import output [as 别名]
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)
示例3: SPIsend
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import output [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)
示例4: test_outputread
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import output [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_loopback
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import output [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()
示例6: testExceptionInCallback
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import output [as 别名]
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)
示例7: reset
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import output [as 别名]
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
示例8: lock
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import output [as 别名]
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
示例9: SPIsendValue
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import output [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
示例10: runTest
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import output [as 别名]
def runTest(self):
# Test mode not set (BOARD or BCM) exception
with self.assertRaises(RuntimeError) as e:
GPIO.setup(LED_PIN, GPIO.OUT)
self.assertEqual(str(e.exception), 'Please set pin numbering mode using GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM)')
GPIO.setmode(GPIO.BOARD)
# Test not set as OUTPUT message
with self.assertRaises(RuntimeError) as e:
GPIO.output(LED_PIN, GPIO.HIGH)
self.assertEqual(str(e.exception), 'The GPIO channel has not been set up as an OUTPUT')
GPIO.setup(LED_PIN, GPIO.IN)
# Test setup(..., pull_up_down=GPIO.HIGH) raises exception
with self.assertRaises(ValueError):
GPIO.setup(LED_PIN, GPIO.IN, pull_up_down=GPIO.HIGH)
# Test 'already in use' warning
GPIO.cleanup()
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()
# test initial value of high reads back as high
GPIO.setup(LED_PIN, GPIO.OUT, initial=GPIO.HIGH)
self.assertEqual(GPIO.input(LED_PIN), GPIO.HIGH)
GPIO.cleanup()
# test initial value of low reads back as low
GPIO.setup(LED_PIN, GPIO.OUT, initial=GPIO.LOW)
self.assertEqual(GPIO.input(LED_PIN), GPIO.LOW)
GPIO.cleanup()
示例11: LNdigital
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import output [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
示例12: SPIread
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import output [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
示例13: testPwm
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import output [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 output [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: testRisingEventDetected
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import output [as 别名]
def testRisingEventDetected(self):
GPIO.output(LOOP_OUT, GPIO.LOW)
GPIO.add_event_detect(LOOP_IN, GPIO.RISING)
time.sleep(0.001)
self.assertEqual(GPIO.event_detected(LOOP_IN), False)
GPIO.output(LOOP_OUT, GPIO.HIGH)
time.sleep(0.001)
self.assertEqual(GPIO.event_detected(LOOP_IN), True)
GPIO.output(LOOP_OUT, GPIO.LOW)
time.sleep(0.001)
self.assertEqual(GPIO.event_detected(LOOP_IN), False)
GPIO.remove_event_detect(LOOP_IN)