本文整理汇总了Python中nanpy.Arduino.digitalRead方法的典型用法代码示例。如果您正苦于以下问题:Python Arduino.digitalRead方法的具体用法?Python Arduino.digitalRead怎么用?Python Arduino.digitalRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nanpy.Arduino
的用法示例。
在下文中一共展示了Arduino.digitalRead方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from nanpy import Arduino [as 别名]
# 或者: from nanpy.Arduino import digitalRead [as 别名]
def main():
while True:
try:
locked = Arduino.digitalRead(lock)
if locked == 0:
debug()
else:
### Actual Avoider coder starts below ###
if not front_bump():
if not left_bump() and not right_bump():
print "No bump detected - on we go!"
go(200)
if left_bump() and not right_bump():
print "Left bump detected... Turning right"
rot_cw(100, 200)
elif right_bump() and not left_bump():
print "Right bump detected... Turning left"
rot_ccw(100, 200)
elif left_bump() and right_bump():
print "Both left & right bumps detected... Turning round!"
rot_cw(500, 200)
else:
print "Front bump detected... Turning round!"
rot_cw(500, 200)
# avoider code ends above
except KeyboardInterrupt:
close_pins()
print "\nExiting"
quit()
示例2: pirSense
# 需要导入模块: from nanpy import Arduino [as 别名]
# 或者: from nanpy.Arduino import digitalRead [as 别名]
def pirSense(self):
for key in self.unit['pir']:
pin = self.unit['pir'][key]['pin']
Arduino.pinMode(pin, Arduino.INPUT)
self.unit['pir'][key].update(state=Arduino.digitalRead(pin))
示例3: digitalpin
# 需要导入模块: from nanpy import Arduino [as 别名]
# 或者: from nanpy.Arduino import digitalRead [as 别名]
def digitalpin(pin_number):
if request.method == 'GET':
Arduino.pinMode(pin_number, Arduino.INPUT)
data = {
'value' : Arduino.digitalRead(pin_number)
}
resp = Response(json.dumps(data), status=200, mimetype='application/json')
return resp
else:
Arduino.pinMode(pin_number, Arduino.OUTPUT)
Arduino.digitalWrite(pin_number, request.json['value'])
resp = Response("", status=200, mimetype='application/json')
return resp
示例4: diode
# 需要导入模块: from nanpy import Arduino [as 别名]
# 或者: from nanpy.Arduino import digitalRead [as 别名]
#!/usr/bin/env python
# Author: Scott Ellis
# Basic Digital Read
# turns on and off a light emitting diode(LED) connected to digital
# pin 13, when pressing a pushbutton attached to pin 5.
# Dependencies: nanpy 0.7
from nanpy import Arduino
sensorButton = Arduino.digitalRead(5)
Arduino.pinMode(sensorButton, Arduino.INPUT)
ledPin = 13;
Arduino.pinMode(ledPin, Arduino.OUTPUT)
while True:
sensorButton = Arduino.digitalRead(5)
print("sensor value: %d" % sensorButton)
if (sensorButton == True):
Arduino.digitalWrite(ledPin, Arduino.HIGH)
else:
Arduino.digitalWrite(ledPin, Arduino.LOW)
Arduino.delay(100)
示例5:
# 需要导入模块: from nanpy import Arduino [as 别名]
# 或者: from nanpy.Arduino import digitalRead [as 别名]
__author__ = 'mc7h'
__license__ = 'None'
from nanpy import Arduino as A
switchstate = 0
# SETUP:
A.pinMode(3, A.OUTPUT)
A.pinMode(4, A.OUTPUT)
A.pinMode(5, A.OUTPUT)
A.pinMode(2, A.INPUT)
# LOOP:
while True:
switchState = A.digitalRead(2)
if switchState == A.LOW:
A.digitalWrite(3, A.HIGH) # turn the green LED on pin 3 on
A.digitalWrite(4, A.LOW) # turn the red LED on pin 4 off
A.digitalWrite(5, A.LOW) # turn the red LED on pin 5 off
else:
A.digitalWrite(3, A.LOW); # turn the green LED on pin 3 off
A.digitalWrite(4, A.LOW); # turn the red LED on pin 4 off
A.digitalWrite(5, A.HIGH); # turn the red LED on pin 5 on
# wait for a quarter second before changing the light
A.delay(250);
A.digitalWrite(4, A.HIGH); #// turn the red LED on pin 4 on
A.digitalWrite(5, A.LOW); #// turn the red LED on pin 5 off
# wait for a quarter second before changing the light