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


Python Arduino.pass_time方法代码示例

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


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

示例1: ArduinoConnection

# 需要导入模块: from pyfirmata import Arduino [as 别名]
# 或者: from pyfirmata.Arduino import pass_time [as 别名]
class ArduinoConnection(Thread):

    def __init__(self):
        Thread.__init__(self)
        
        self.SAMPLING_INTERVAL = 0.100
        self.MEAN_INTERVAL = 5
        self.MEAN_SAMPLES_NUMBER = round(self.MEAN_INTERVAL/self.SAMPLING_INTERVAL)

        PORT = '/dev/ttyACM0'
        self.board = Arduino(PORT)
        it = util.Iterator(self.board)
        it.start()

        self.analog_pin_value_arr = [self.board.get_pin('a:0:i'), self.board.get_pin('a:1:i'), self.board.get_pin('a:2:i'), self.board.get_pin('a:3:i'), self.board.get_pin('a:4:i'), self.board.get_pin('a:5:i')]
        for i in range(len(self.analog_pin_value_arr)):
            self.analog_pin_value_arr[i].enable_reporting()

        self.mean_analog_valuea_arr = [0.0] * 6
        self.mean_analog_valuea_assigned_arr = [0.0] * 6

    def run(self):        
        #s= ''
        sample_number = 0
        
        while True:
            while (sample_number < self.MEAN_SAMPLES_NUMBER):
                #    time.sleep(DELAY)
                self.board.pass_time(self.SAMPLING_INTERVAL)
                for i in range(len(self.mean_analog_valuea_arr)):
                    self.mean_analog_valuea_arr[i] = self.mean_analog_valuea_arr [i] + self.analog_pin_value_arr[i].read()
                sample_number = sample_number + 1

            for i in range(len(self.mean_analog_valuea_arr)):
                self.mean_analog_valuea_arr[i] = self.mean_analog_valuea_arr[i] / self.MEAN_SAMPLES_NUMBER
                #s = s + str(self.mean_analog_valuea_arr[i]) + ' '

            self.mean_analog_valuea_assigned_arr = self.mean_analog_valuea_arr
                
            #print s
            
            #s = ''            
            sample_number = 0
            self.mean_analog_valuea_arr = [0.0] * 6

    def getMeanAnalogArduinoValueArray(self):
        return self.mean_analog_valuea_assigned_arr
开发者ID:wadiskth,项目名称:tempSens,代码行数:49,代码来源:arduino_connection.py

示例2: Arduino

# 需要导入模块: from pyfirmata import Arduino [as 别名]
# 或者: from pyfirmata.Arduino import pass_time [as 别名]
#!/usr/bin/python
from pyfirmata import Arduino, util

PIN = 12 # Pin 12 is used
DELAY = 2 # A 2 seconds delay

PORT = '/dev/ttyACM0'
board = Arduino(PORT)

while True:
    board.digital[PIN].write(1) # Set the LED pin to 1 (HIGH)
    board.pass_time(DELAY)
    board.digital[PIN].write(0) # Set the LED pin to 0 (LOW)
    board.pass_time(DELAY)
开发者ID:barif,项目名称:raspberry-web-tools,代码行数:16,代码来源:blink.py


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