本文整理匯總了Python中pyb.Timer.prescaler方法的典型用法代碼示例。如果您正苦於以下問題:Python Timer.prescaler方法的具體用法?Python Timer.prescaler怎麽用?Python Timer.prescaler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyb.Timer
的用法示例。
在下文中一共展示了Timer.prescaler方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: UltraSonicMeter
# 需要導入模塊: from pyb import Timer [as 別名]
# 或者: from pyb.Timer import prescaler [as 別名]
class UltraSonicMeter(object):
def __init__(self):
self.tmp = self.time = 0
self.cnt = 0
self.fr = 0
self.trig = Pin('X12', Pin.OUT_PP, Pin.PULL_NONE)
echoR = Pin('X1', Pin.IN, Pin.PULL_NONE)
echoF = Pin('X2', Pin.IN, Pin.PULL_NONE)
self.micros = pyb.Timer(5, prescaler=83, period=0x3fffffff)
self.timer = Timer(2, freq=1000)
self.timer.period(3600)
self.timer.prescaler(1375)
self.timer.callback(lambda e: self.run_trig())
extR = ExtInt(echoR, ExtInt.IRQ_RISING, Pin.PULL_NONE, self.start_count)
extF = ExtInt(echoF, ExtInt.IRQ_FALLING, Pin.PULL_NONE, self.read_dist)
def run_trig(self):
self.trig.high()
pyb.udelay(1)
self.trig.low()
def start_count(self, line):
self.micros.counter(0)
self.time = self.micros.counter()
self.timer.counter(0)
def read_dist(self, line):
end = self.micros.counter()
micros = end-self.time
distP1 = micros//5
distP2 = micros//6
distP3 = (distP1-distP2)//10*2
dist = distP2+distP3
if dist != 0:
self.cnt += 1
self.fr += dist
if self.cnt == 15:
tmp = self.tmp
dist = self.fr//self.cnt
if tmp != dist:
print(dist, 'mm')
self.tmp = dist
self.cnt = 0
self.fr = 0
示例2: Timer
# 需要導入模塊: from pyb import Timer [as 別名]
# 或者: from pyb.Timer import prescaler [as 別名]
# check basic functionality of the timer class
import pyb
from pyb import Timer
tim = Timer(4)
tim = Timer(4, prescaler=100, period=200)
print(tim.prescaler())
print(tim.period())
tim.prescaler(300)
print(tim.prescaler())
tim.period(400)
print(tim.period())