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


Python Timer.deinit方法代码示例

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


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

示例1: rate

# 需要导入模块: from pyb import Timer [as 别名]
# 或者: from pyb.Timer import deinit [as 别名]
class Motor:
    _index = None

    _pin = None
    _timer = None
    _channel = None
    _rate = None

    _rate_min = None
    _rate_max = None

    # Each range represents 50% of the complete range
    _step = None

    _debug = False

    # ########################################################################
    # ### Properties
    # ########################################################################
    @property
    def rate(self):
        return self._rate

    @rate.setter
    def rate(self, value):
        self._rate = max(min(value, 100), 0)
        pulse_value = int(self._rate_min + self._rate * self._step)

        if not self._debug:
            self._channel.pulse_width(pulse_value)
        else:
            print("<<ESC>> %s: %.3d" % (self._pin, self._rate))

    # ########################################################################
    # ### Constructors and destructors
    # ########################################################################
    def __init__(self, esc_index, rate_min=1000, rate_max=2000, debug=False):
        if esc_index >= 0 & esc_index <= 3:
            self._debug = debug
            self._rate_min = rate_min
            self._rate_max = rate_max
            self._step = (rate_max - rate_min) / 100
            self._index = esc_index
            self._pin = ESC_PIN[esc_index]
            self._timer = Timer(ESC_TIMER[esc_index], prescaler=83, period=19999)
            self._channel = self._timer.channel(ESC_CHANNEL[esc_index], Timer.PWM, pin=Pin(self._pin))
            self.rate = 0
        else:
            raise Exception("Invalid ESC index")

    def __del__(self):
        self.rate(self._rate_min)
        self._timer.deinit()
开发者ID:sbollaerts,项目名称:barequadx,代码行数:55,代码来源:Motor.py

示例2: __init__

# 需要导入模块: from pyb import Timer [as 别名]
# 或者: from pyb.Timer import deinit [as 别名]
class ESC:
  freq_min = 950
  freq_max = 1950
  def __init__(self, index):
    self.timer = Timer(esc_pins_timers[index], prescaler=83, period=19999)
    self.channel = self.timer.channel(esc_pins_channels[index],
                                      Timer.PWM,
                                      pin=Pin(esc_pins[index]))
    self.trim = esc_trim[index]
  def move(self, freq):
    freq = min(self.freq_max, max(self.freq_min, freq + self.trim))
    self.channel.pulse_width(int(freq))
  def __del__(self):
    self.timer.deinit()
开发者ID:wagnerc4,项目名称:flight_controller,代码行数:16,代码来源:esc.py

示例3: Stepper

# 需要导入模块: from pyb import Timer [as 别名]
# 或者: from pyb.Timer import deinit [as 别名]
       while pyb.millis() <= now + ms:
          n = (n + 1) % 4
          leds[n].toggle()
          pyb.delay(50)
    finally:
        for l in leds:
            l.off()

from nemastepper import Stepper
motor1 = Stepper('Y1','Y2','Y3')

from pyb import Timer

def step_cb(t):
    motor1.do_step()
    
tim = Timer(8,freq=10000)
tim.callback(step_cb) #start interrupt routine

motor1.MAX_ACCEL = 1000
motor1.set_speed(1000)
disco(1000)  
motor1.set_speed(0)
motor1.set_speed(-1000)
disco(1000) 

motor1.set_speed(0)
motor1.set_off()

tim.deinit()
开发者ID:elfnor,项目名称:micropython-blog-examples,代码行数:32,代码来源:stepper_with_nemastepper.py

示例4: SR04Distance

# 需要导入模块: from pyb import Timer [as 别名]
# 或者: from pyb.Timer import deinit [as 别名]
class SR04Distance(object):
  """  """

  maxinches = 20 #maximum range of SR04.

  def __init__( self, tpin, epin, timer=2 ) :
    """  """

    if type(tpin) == str:
      self._tpin = Pin(tpin, Pin.OUT_PP, Pin.PULL_NONE)
    elif type(tpin) == Pin:
      self._tpin = tpin
    else:
      raise Exception("trigger pin must be pin name or pyb.Pin configured for output.")

    self._tpin.low()

    if type(epin) == str:
      self._epin = Pin(epin, Pin.IN, Pin.PULL_NONE)
    elif type(epin) == Pin:
      self._epin = epin
    else:
      raise Exception("echo pin must be pin name or pyb.Pin configured for input.")

    # Create a microseconds counter.
    self._micros = Timer(timer, prescaler=83, period=0x3fffffff)

  def __del__( self ) :
    self._micros.deinit()

  @property
  def counter( self ) : return self._micros.counter()

  @counter.setter
  def counter( self, value ) : self._micros.counter(value)

  @property
  def centimeters( self ) :
    start = 0
    end = 0

    self.counter = 0

    #Send 10us pulse.
    self._tpin.high()
    udelay(10)
    self._tpin.low()

    while not self._epin.value():
      start = self.counter

    j = 0

    # Wait 'till the pulse is gone.
    while self._epin.value() and j < 1000:
      j += 1
      end = self.counter

    # Calc the duration of the recieved pulse, divide the result by
    # 2 (round-trip) and divide it by 29 (the speed of sound is
    # 340 m/s and that is 29 us/cm).
    return (end - start) / 58

  @property
  def inches( self ) : return self.centimeters * 0.3937
开发者ID:rolandvs,项目名称:GuyCarverMicroPythonCode,代码行数:67,代码来源:SR04Distance.py


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