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


Python machine.PWM属性代码示例

本文整理汇总了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) 
开发者ID:IBM-Developer-Korea,项目名称:developer-badge-2018-apps,代码行数:25,代码来源:buzzer.py

示例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() 
开发者ID:IBM-Developer-Korea,项目名称:developer-badge-2018-apps,代码行数:24,代码来源:buzzer.py

示例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 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:18,代码来源:esp_8266Full.py

示例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) 
开发者ID:BlackLight,项目名称:platypush,代码行数:21,代码来源:__init__.py

示例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) 
开发者ID:BlackLight,项目名称:platypush,代码行数:21,代码来源:__init__.py

示例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) 
开发者ID:BlackLight,项目名称:platypush,代码行数:26,代码来源:__init__.py

示例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) 
开发者ID:BlackLight,项目名称:platypush,代码行数:18,代码来源:__init__.py

示例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) 
开发者ID:1zlab,项目名称:1ZLAB_PyEspCar,代码行数:25,代码来源:motor.py

示例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() 
开发者ID:ulno,项目名称:ulnoiot-upy,代码行数:19,代码来源:servo.py

示例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) 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:6,代码来源:speak.py

示例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) 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:10,代码来源:easyIO.py

示例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) 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:10,代码来源:_servo.py

示例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) 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:17,代码来源:_ir.py

示例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() 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:11,代码来源:esp_8266Full.py

示例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']) 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:9,代码来源:esp_8266Full.py


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