本文整理汇总了Python中pyb.Timer.freq方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.freq方法的具体用法?Python Timer.freq怎么用?Python Timer.freq使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyb.Timer
的用法示例。
在下文中一共展示了Timer.freq方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PWM
# 需要导入模块: from pyb import Timer [as 别名]
# 或者: from pyb.Timer import freq [as 别名]
class PWM(object):
"""docstring for PWMM"""
#Dict pin name: timer #, channel #.
PinChannels = {
'X1': [(2,1), (5,1)],
'X2': [(2,2), (5,2)],
'X3': [(2,3), (5,3), (9,1)],
'X4': [(2,4), (5,4), (9,2)],
'X6': [(2,1), (8,1)],
'X7': [(13, 1)],
'X8': [(1,1), (8,1), (14,1)],
'X9': [(4,1)],
'X10': [(4,2)],
'Y1': [(8,1)],
'Y2': [(8,2)],
'Y3': [(4,3), (10,1)],
'Y4': [(4,4), (11,1)],
'Y6': [(1,1)],
'Y7': [(1,2), (8,2), (12,1)],
'Y8': [(1,3), (8,3), (12,2)],
'Y9': [(2,3)],
'Y10': [(2,4)],
'Y11': [(1,2), (8,2)],
'Y12': [(1,3), (8,3)]
}
class PWMException(Exception):
def __init__( self, msg ) :
self.msg = msg
@staticmethod
def timerandchannel( pinname, timernum ) :
try:
a = PWM.PinChannels[pinname]
if timernum <= 0:
return a[0]
else:
for v in a:
if v[0] == timernum:
return v
except Exception as e :
raise PWM.PWMException("Pin {} cannot be used for PWM".format(pinname))
raise PWM.PWMException("Pin {} cannot use timer {}".format(pinname, timernum))
def __init__( self, p, timernum, afreq = 100 ) :
isname = type(p) == str
pinname = p if isname else p.name()
timernum, channel = PWM.timerandchannel(pinname, timernum)
if isname:
p = Pin(pinname)
self._timer = Timer(timernum, freq = afreq)
self._channel = self._timer.channel(channel, Timer.PWM, pin = p)
@property
def pulse_width( self ) : return self._channel.pulse_width()
@pulse_width.setter
def pulse_width( self, value ) : self._channel.pulse_width(value)
@property
def pulse_width_percent( self ) : return self._channel.pulse_width_percent()
@pulse_width_percent.setter
def pulse_width_percent( self, value ) : self._channel.pulse_width_percent(value)
@property
def freq( self ) : return self._timer.freq()
@freq.setter
def freq( self, value ) : self._timer.freq(value)
def callback( self, value ) :
self._channel.callback(value)