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


Python Arduino.digitalRead方法代码示例

本文整理汇总了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()
开发者ID:russb78,项目名称:RDuD2,代码行数:31,代码来源:nanpy_avoider.py

示例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))
开发者ID:walln3r,项目名称:home,代码行数:10,代码来源:aio.py

示例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
开发者ID:RobertJamesMason,项目名称:eggsamples,代码行数:15,代码来源:arduino.py

示例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)
开发者ID:scottellis-,项目名称:candle_project,代码行数:26,代码来源:push_buttonConstantOn.py

示例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
开发者ID:mc7h,项目名称:arduino-starterkit-using-nanpy,代码行数:33,代码来源:spaceship_interface.py


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