本文整理汇总了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()
示例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()
示例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()
示例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