本文整理匯總了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