本文整理匯總了Python中machine.PWM屬性的典型用法代碼示例。如果您正苦於以下問題:Python machine.PWM屬性的具體用法?Python machine.PWM怎麽用?Python machine.PWM使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類machine
的用法示例。
在下文中一共展示了machine.PWM屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import machine [as 別名]
# 或者: from machine import PWM [as 別名]
def __init__(self):
self.notes = {
'cdef': [
self.C6, self.D6, self.E6, self.F6, self.G6, self.A6, self.B6, self.C7, self.D7, self.E7, self.F7, self.G7, self.A7, self.B7, self.C8, 0
],
'mario': [
self.E7, self.E7, 0, self.E7, 0, self.C7, self.E7, 0, self.G7, 0, 0, 0, self.G6, 0, 0, 0,
self.C7, 0, 0, self.G6, 0, 0, self.E6, 0, 0, self.A6, 0, self.B6, 0, self.AS6, self.A6, 0,
self.G6, self.E7, 0, self.G7, self.A7, 0, self.F7, self.G7, 0, self.E7, 0, self.C7, self.D7, self.B6, 0, 0,
self.C7, 0, 0, self.G6, 0, 0, self.E6, 0, 0, self.A6, 0, self.B6, 0, self.AS6, self.A6, 0,
self.G6, self.E7, 0, self.G7, self.A7, 0, self.F7, self.G7, 0, self.E7, 0, self.C7, self.D7, self.B6, 0, 0
],
'starwars': [
self.A4, 0, 0, 0, self.A4, 0, 0, 0, self.A4, 0, 0, 0, self.F4, 0, 0, self.C5,
self.A4, 0, 0, 0, self.F4, 0, 0, self.C5, self.A4, 0, 0, 0, 0, 0, 0, 0,
self.E5, 0, 0, 0, self.E5, 0, 0, 0, self.E5, 0, 0, 0, self.F5, 0, 0, self.C5,
self.GS4, 0, 0, 0, self.F4, 0, 0, self.C5, self.A4, 0, 0, 0, 0, 0, 0, 0,
],
}
# Init
self.pwm = PWM(Pin(27, Pin.OUT))
self.pwm.duty(0)
示例2: playnotes
# 需要導入模塊: import machine [as 別名]
# 或者: from machine import PWM [as 別名]
def playnotes(self, title, length=150, duty=64):
# Init
p = Pin(27, Pin.OUT)
self.pwm = PWM(p)
self.pwm.duty(0)
if title not in self.notes:
print('unknown title: {}'.format(title))
return
melody = self.notes[title]
print('Play', title)
for i in melody:
if i == 0:
self.pwm.duty(0)
else:
self.pwm.freq(i)
self.pwm.duty(duty)
time.sleep_ms(length)
# deinit
self.pwm.deinit()
示例3: digital_write
# 需要導入模塊: import machine [as 別名]
# 或者: from machine import PWM [as 別名]
def digital_write(self, payload):
"""
Write to a digital gpio pin
:param payload:
:return:
"""
pin = payload['pin']
mode = Pin.OUT
if 'drain' in payload:
if not payload['drain']:
mode = Pin.OPEN_DRAIN
pin_object = Pin(pin, mode)
pwm = PWM(pin_object)
pwm.deinit()
Pin(pin, mode, value=payload['value'])
self.input_pin_objects[pin] = None
示例4: pwm_freq
# 需要導入模塊: import machine [as 別名]
# 或者: from machine import PWM [as 別名]
def pwm_freq(self, pin: Union[int, str], freq: Optional[int] = None, **kwargs) -> Optional[int]:
"""
Get/set the frequency of a PWM PIN.
:param pin: GPIO PIN number or configured name.
:param freq: If set, set the frequency for the PIN in Hz.
:param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.execute`.
"""
device = self._get_device(**kwargs)
pin = device.get_pin(pin)
code = '''
import machine
pin = machine.PWM(machine.Pin({pin}))
pin.freq({freq})
'''.format(pin=pin, freq=freq if freq else '')
ret = self.execute(code, **kwargs).output
if not freq:
return int(ret)
示例5: pwm_duty
# 需要導入模塊: import machine [as 別名]
# 或者: from machine import PWM [as 別名]
def pwm_duty(self, pin: Union[int, str], duty: Optional[int] = None, **kwargs) -> Optional[int]:
"""
Get/set the duty cycle of a PWM PIN.
:param pin: GPIO PIN number or configured name.
:param duty: Optional duty value to set.
:param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.execute`.
"""
device = self._get_device(**kwargs)
pin = device.get_pin(pin)
code = '''
import machine
pin = machine.PWM(machine.Pin({pin}))
pin.duty({duty})
'''.format(pin=pin, duty=duty if duty else '')
ret = self.execute(code, **kwargs).output
if not duty:
return int(ret)
示例6: pwm_on
# 需要導入模塊: import machine [as 別名]
# 或者: from machine import PWM [as 別名]
def pwm_on(self, pin: Union[int, str], freq: Optional[int] = None, duty: Optional[int] = None, **kwargs):
"""
Set the specified PIN to HIGH.
:param pin: GPIO PIN number or configured name.
:param freq: PWM PIN frequency.
:param duty: PWM PIN duty cycle.
:param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.execute`.
"""
device = self._get_device(**kwargs)
pin = device.get_pin(pin)
code = '''
import machine
pin = machine.PWM(machine.Pin({pin}))
if {freq}:
pin.freq({freq})
if {duty}:
pin.duty({duty})
pin.on()
'''.format(pin=pin, freq=freq, duty=duty)
self.execute(code, **kwargs)
示例7: pwm_off
# 需要導入模塊: import machine [as 別名]
# 或者: from machine import PWM [as 別名]
def pwm_off(self, pin: Union[int, str], **kwargs):
"""
Turn off a PWM PIN.
:param pin: GPIO PIN number or configured name.
:param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.execute`.
"""
device = self._get_device(**kwargs)
pin = device.get_pin(pin)
code = '''
import machine
pin = machine.PWM(machine.Pin({pin}))
pin.deinit()
'''.format(pin=pin)
self.execute(code, **kwargs)
示例8: __init__
# 需要導入模塊: import machine [as 別名]
# 或者: from machine import PWM [as 別名]
def __init__(self, idx, is_debug=False):
gpio_a, gpio_b, self.motor_install_dir = Motor.MOTOR_LIST[idx]
# A相PWM
self.pwm_a = PWM(
Pin(gpio_a, Pin.OUT),
freq = Motor.MOTOR_PWM_FREQUENCY,
duty = 0)
# B相PWM
self.pwm_b = PWM(
Pin(gpio_b, Pin.OUT),
freq = Motor.MOTOR_PWM_FREQUENCY,
duty = 0)
# 電機安裝方向
if not self.motor_install_dir:
self.pwm_a, self.pwm_b = self.pwm_b, self.pwm_a
# 電機速度信號 取值範圍: -1023 - 1023
self._pwm = 0
# 設置電機的PWM
# self.pwm(self._pwm)
示例9: __init__
# 需要導入模塊: import machine [as 別名]
# 或者: from machine import PWM [as 別名]
def __init__(self, name, pin,
ignore_case=True, on_change=None,
report_change=False,
turn_time_ms=700,
freq=50, min_us=600, max_us=2400, angle=180):
self.min_us = min_us
self.max_us = max_us
self.us = 0
self.freq = freq
self.angle = angle
self.angle_list = None
self.turn_time_ms = turn_time_ms
self.turn_start = None
Device.__init__(self, name, PWM(pin, freq=self.freq, duty=0),
setters={"set": self.turn}, ignore_case=ignore_case,
on_change=on_change, report_change=report_change)
self._init()
示例10: checkInit
# 需要導入模塊: import machine [as 別名]
# 或者: from machine import PWM [as 別名]
def checkInit(self):
if self.pwm_init == False:
self.pwm_init = True
self.pwm = machine.PWM(machine.Pin(self.pin, value=0), freq = 1, duty = 0, timer = 2)
示例11: analogWrite
# 需要導入模塊: import machine [as 別名]
# 或者: from machine import PWM [as 別名]
def analogWrite(pin, duty):
if pin not in _pwm_map.keys():
try:
_pwm_map[pin] = PWM(pin, duty=duty, timer=1)
except:
pass
else:
_pwm_map[pin].duty(duty)
示例12: __init__
# 需要導入模塊: import machine [as 別名]
# 或者: from machine import PWM [as 別名]
def __init__(self, port, freq=50, min_us=500, max_us=2500, angle=180):
self.min_us = min_us
self.max_us = max_us
self.us = 0
self.freq = freq
self.angle = angle
self.port = port
self.pwm = PWM(port[0], freq=freq, duty=0, timer=3)
示例13: __init__
# 需要導入模塊: import machine [as 別名]
# 或者: from machine import PWM [as 別名]
def __init__(self, port):
self.tx = PWM(port[0], freq=38000, duty=0, timer=1)
self.rx = Pin(port[1], Pin.IN)
self.rx.init(Pin.IN)
self.rx.irq(handler=self._irq_cb, trigger=Pin.IRQ_FALLING)
self.rx_value = 0
self.times = 0
self.status = 0
self.tx_en = 0
self.duty = 0
self.time_num = peripheral.get_timer()
if self.time_num == None:
raise unit.Unit('ir application time fail')
self.timer = Timer(self.time_num)
self.timer.init(period=50, mode=self.timer.PERIODIC, callback=self._update)
示例14: play_tone
# 需要導入模塊: import machine [as 別名]
# 或者: from machine import PWM [as 別名]
def play_tone(self, payload):
"""
Play a tone on the specified pin
:param payload:
:return:
"""
beeper = PWM(Pin(payload['pin']), freq=payload['freq'], duty=512)
utime.sleep_ms(payload['duration'])
beeper.deinit()
示例15: pwm_write
# 需要導入模塊: import machine [as 別名]
# 或者: from machine import PWM [as 別名]
def pwm_write(self, payload):
"""
Write a value to a PWM pin
:param payload:
:return:
"""
PWM(Pin(payload['pin']), freq=500, duty=payload['value'])