本文整理汇总了Python中LMK.GPIO类的典型用法代码示例。如果您正苦于以下问题:Python GPIO类的具体用法?Python GPIO怎么用?Python GPIO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GPIO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testWaitForFalling
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
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: test_switchbounce
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: test_loopback
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: test_outputread
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: test_cleanall
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: test_event_detected
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: lock
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: reset
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
示例10: handler
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: testExceptionInCallback
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)
示例12: testEventDetect
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)
示例13: SPIsend
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: runTest
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: testPwm
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()