当前位置: 首页>>代码示例>>Python>>正文


Python GPIO.input方法代码示例

本文整理汇总了Python中LMK.GPIO.input方法的典型用法代码示例。如果您正苦于以下问题:Python GPIO.input方法的具体用法?Python GPIO.input怎么用?Python GPIO.input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LMK.GPIO的用法示例。


在下文中一共展示了GPIO.input方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_outputread

# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import input [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()
开发者ID:Alessia-Cao,项目名称:LMK.GPIO,代码行数:10,代码来源:test.py

示例2: test_loopback

# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import input [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()
开发者ID:Alessia-Cao,项目名称:LMK.GPIO,代码行数:10,代码来源:test.py

示例3: runTest

# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import input [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()
开发者ID:Alessia-Cao,项目名称:LMK.GPIO,代码行数:45,代码来源:test.py

示例4: range

# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import input [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)
开发者ID:Alessia-Cao,项目名称:LMK.GPIO,代码行数:22,代码来源:polling_RAW.py

示例5: testEventDetect

# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import input [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)
开发者ID:LeMaker,项目名称:LMK.GPIO,代码行数:15,代码来源:event_detect.py

示例6: SPIread

# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import input [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
开发者ID:Alessia-Cao,项目名称:LeScratch,代码行数:16,代码来源:LeScratch.py

示例7: calDistance

# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import input [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
开发者ID:Alessia-Cao,项目名称:LeScratch,代码行数:25,代码来源:LeScratch.py

示例8:

# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import input [as 别名]
#!/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()
开发者ID:Alessia-Cao,项目名称:LMK.GPIO,代码行数:21,代码来源:led_read.py

示例9: my_callback

# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import input [as 别名]
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"
开发者ID:hunanchenxingyu,项目名称:LMK.GPIO,代码行数:6,代码来源:add_event_detect_RAW.py

示例10:

# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import input [as 别名]
#!/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)
开发者ID:Alessia-Cao,项目名称:LMK.GPIO,代码行数:23,代码来源:event_detect.py

示例11: soundDetect

# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import input [as 别名]
def soundDetect(channel):
    print("Sound detect on GPIO %d is %d" %(soundPin, GPIO.input(soundPin)))
    sendCmd("sensor-update soundDetect %d" % (GPIO.input(soundPin)))
开发者ID:Alessia-Cao,项目名称:LeScratch,代码行数:5,代码来源:LeScratch.py

示例12:

# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import input [as 别名]
#!/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()
开发者ID:Alessia-Cao,项目名称:LMK.GPIO,代码行数:19,代码来源:gpio_pull.py

示例13: my_callback

# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import input [as 别名]
#LED Mode BOARD
#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]
#[3,5,7,8,12,16,18,19,21,23,24,26,27,28,29,31,32,33,35,36,37,38,40]
#[10,11,13,15,22]
#GPIO.setmode(GPIO.BOARD)

#Switch BCM [4,14,23,24,10,9,11,8,7]
#Switch BOARD [7,8,16,18,19,21,23,24,26]   18,19,26
PIN_NUM = 24
GPIO.setmode(GPIO.BCM)
#GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIN_NUM,GPIO.IN,GPIO.PUD_UP)


print "The value of Pin %d is %d" %(PIN_NUM,GPIO.input(PIN_NUM))


def my_callback(channel):
	print "The value of Pin %d is %d" %(PIN_NUM,GPIO.input(PIN_NUM))

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

GPIO.add_event_detect(PIN_NUM,GPIO.RISING,callback = my_callback,bouncetime = 300)


print "The value of Pin %d is %d" %(PIN_NUM,GPIO.input(PIN_NUM))

开发者ID:Alessia-Cao,项目名称:LMK.GPIO,代码行数:30,代码来源:add_event_detect.py

示例14:

# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import input [as 别名]
'''
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()
开发者ID:LeMaker,项目名称:LMK.GPIO,代码行数:28,代码来源:gpio_input.py

示例15: makehigh

# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import input [as 别名]
def makehigh():
	print "\n value_%d = %d\n" %(channel,GPIO.input(channel))
	GPIO.output(PIN_NUM,False)
	print "\n value_%d = %d\n" %(PIN_NUM,GPIO.input(PIN_NUM))
开发者ID:Alessia-Cao,项目名称:LMK.GPIO,代码行数:6,代码来源:wait_for_edge.py


注:本文中的LMK.GPIO.input方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。