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


Python mock.MockPWMPin类代码示例

本文整理汇总了Python中gpiozero.pins.mock.MockPWMPin的典型用法代码示例。如果您正苦于以下问题:Python MockPWMPin类的具体用法?Python MockPWMPin怎么用?Python MockPWMPin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MockPWMPin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_output_pwm_fade_foreground

def test_output_pwm_fade_foreground():
    pin = MockPWMPin(2)
    device = PWMOutputDevice(pin)
    device.blink(0, 0, 0.1, 0.1, n=2, background=False)
    pin.assert_states_and_times([
        (0.0, 0),
        (0.02, 0.2),
        (0.02, 0.4),
        (0.02, 0.6),
        (0.02, 0.8),
        (0.02, 1),
        (0.02, 0.8),
        (0.02, 0.6),
        (0.02, 0.4),
        (0.02, 0.2),
        (0.02, 0),
        (0.02, 0.2),
        (0.02, 0.4),
        (0.02, 0.6),
        (0.02, 0.8),
        (0.02, 1),
        (0.02, 0.8),
        (0.02, 0.6),
        (0.02, 0.4),
        (0.02, 0.2),
        (0.02, 0),
        ])
开发者ID:DeeJay,项目名称:python-gpiozero,代码行数:27,代码来源:test_outputs.py

示例2: test_output_pwm_blink_interrupt

def test_output_pwm_blink_interrupt():
    pin = MockPWMPin(2)
    with PWMOutputDevice(pin) as device:
        device.blink(1, 0.1)
        sleep(0.2)
        device.off() # should interrupt while on
        pin.assert_states([0, 1, 0])
开发者ID:EdwardBetts,项目名称:python-gpiozero,代码行数:7,代码来源:test_outputs.py

示例3: test_output_pwm_pulse_foreground

def test_output_pwm_pulse_foreground():
    pin = MockPWMPin(2)
    with PWMOutputDevice(pin) as device:
        start = time()
        device.pulse(0.2, 0.2, n=2, background=False)
        assert isclose(time() - start, 0.8, abs_tol=0.05)
        pin.assert_states_and_times([
            (0.0, 0),
            (0.04, 0.2),
            (0.04, 0.4),
            (0.04, 0.6),
            (0.04, 0.8),
            (0.04, 1),
            (0.04, 0.8),
            (0.04, 0.6),
            (0.04, 0.4),
            (0.04, 0.2),
            (0.04, 0),
            (0.04, 0.2),
            (0.04, 0.4),
            (0.04, 0.6),
            (0.04, 0.8),
            (0.04, 1),
            (0.04, 0.8),
            (0.04, 0.6),
            (0.04, 0.4),
            (0.04, 0.2),
            (0.04, 0),
            ])
开发者ID:EdwardBetts,项目名称:python-gpiozero,代码行数:29,代码来源:test_outputs.py

示例4: test_led_bar_graph_pwm_value

def test_led_bar_graph_pwm_value():
    pin1 = MockPWMPin(2)
    pin2 = MockPWMPin(3)
    pin3 = MockPWMPin(4)
    with LEDBarGraph(pin1, pin2, pin3, pwm=True) as graph:
        assert isinstance(graph[0], PWMLED)
        assert isinstance(graph[1], PWMLED)
        assert isinstance(graph[2], PWMLED)
        graph.value = 0
        assert graph.value == 0
        assert not any((pin1.state, pin2.state, pin3.state))
        graph.value = 1
        assert graph.value == 1
        assert all((pin1.state, pin2.state, pin3.state))
        graph.value = 1/3
        assert graph.value == 1/3
        assert pin1.state and not (pin2.state or pin3.state)
        graph.value = -1/3
        assert graph.value == -1/3
        assert pin3.state and not (pin1.state or pin2.state)
        graph.value = 1/2
        assert graph.value == 1/2
        assert (pin1.state, pin2.state, pin3.state) == (1, 0.5, 0)
        pin1.state = 0
        pin3.state = 1
        assert graph.value == -1/2
开发者ID:EdwardBetts,项目名称:python-gpiozero,代码行数:26,代码来源:test_boards.py

示例5: test_output_pwm_states

def test_output_pwm_states():
    pin = MockPWMPin(2)
    with PWMOutputDevice(pin) as device:
        device.value = 0.1
        device.value = 0.2
        device.value = 0.0
        pin.assert_states([0.0, 0.1, 0.2, 0.0])
开发者ID:EdwardBetts,项目名称:python-gpiozero,代码行数:7,代码来源:test_outputs.py

示例6: test_output_pwm_fade_background

def test_output_pwm_fade_background():
    pin = MockPWMPin(2)
    with PWMOutputDevice(pin) as device:
        start = time()
        device.blink(0, 0, 0.2, 0.2, n=2)
        assert isclose(time() - start, 0, abs_tol=0.05)
        device._blink_thread.join()
        assert isclose(time() - start, 0.8, abs_tol=0.05)
        pin.assert_states_and_times([
            (0.0, 0),
            (0.04, 0.2),
            (0.04, 0.4),
            (0.04, 0.6),
            (0.04, 0.8),
            (0.04, 1),
            (0.04, 0.8),
            (0.04, 0.6),
            (0.04, 0.4),
            (0.04, 0.2),
            (0.04, 0),
            (0.04, 0.2),
            (0.04, 0.4),
            (0.04, 0.6),
            (0.04, 0.8),
            (0.04, 1),
            (0.04, 0.8),
            (0.04, 0.6),
            (0.04, 0.4),
            (0.04, 0.2),
            (0.04, 0),
            ])
开发者ID:EdwardBetts,项目名称:python-gpiozero,代码行数:31,代码来源:test_outputs.py

示例7: test_output_pwm_fade_background

def test_output_pwm_fade_background():
    pin = MockPWMPin(2)
    device = PWMOutputDevice(pin)
    device.blink(0, 0, 0.1, 0.1, n=2)
    device._blink_thread.join()
    pin.assert_states_and_times([
        (0.0, 0),
        (0.02, 0.2),
        (0.02, 0.4),
        (0.02, 0.6),
        (0.02, 0.8),
        (0.02, 1),
        (0.02, 0.8),
        (0.02, 0.6),
        (0.02, 0.4),
        (0.02, 0.2),
        (0.02, 0),
        (0.02, 0.2),
        (0.02, 0.4),
        (0.02, 0.6),
        (0.02, 0.8),
        (0.02, 1),
        (0.02, 0.8),
        (0.02, 0.6),
        (0.02, 0.4),
        (0.02, 0.2),
        (0.02, 0),
        ])
开发者ID:DeeJay,项目名称:python-gpiozero,代码行数:28,代码来源:test_outputs.py

示例8: test_mock_pin_frequency_supported

def test_mock_pin_frequency_supported():
    pin = MockPWMPin(3)
    pin.function = 'output'
    assert pin.frequency is None
    pin.frequency = 100
    pin.state = 0.5
    pin.frequency = None
    assert not pin.state
开发者ID:alaudet,项目名称:python-gpiozero,代码行数:8,代码来源:test_mock_pin.py

示例9: test_output_pwm_toggle

def test_output_pwm_toggle():
    pin = MockPWMPin(2)
    with PWMOutputDevice(pin) as device:
        device.toggle()
        device.value = 0.5
        device.value = 0.1
        device.toggle()
        device.off()
        pin.assert_states([False, True, 0.5, 0.1, 0.9, False])
开发者ID:EdwardBetts,项目名称:python-gpiozero,代码行数:9,代码来源:test_outputs.py

示例10: test_led_board_fade_background

def test_led_board_fade_background():
    pin1 = MockPWMPin(2)
    pin2 = MockPWMPin(3)
    pin3 = MockPWMPin(4)
    with LEDBoard(pin1, LEDBoard(pin2, pin3, pwm=True), pwm=True) as board:
        board.blink(0, 0, 0.2, 0.2, n=2)
        board._blink_thread.join()
        test = [
            (0.0, 0),
            (0.04, 0.2),
            (0.04, 0.4),
            (0.04, 0.6),
            (0.04, 0.8),
            (0.04, 1),
            (0.04, 0.8),
            (0.04, 0.6),
            (0.04, 0.4),
            (0.04, 0.2),
            (0.04, 0),
            (0.04, 0.2),
            (0.04, 0.4),
            (0.04, 0.6),
            (0.04, 0.8),
            (0.04, 1),
            (0.04, 0.8),
            (0.04, 0.6),
            (0.04, 0.4),
            (0.04, 0.2),
            (0.04, 0),
            ]
        pin1.assert_states_and_times(test)
        pin2.assert_states_and_times(test)
        pin3.assert_states_and_times(test)
开发者ID:ChiangFamily,项目名称:python-gpiozero,代码行数:33,代码来源:test_boards.py

示例11: test_output_pwm_blink_foreground

def test_output_pwm_blink_foreground():
    pin = MockPWMPin(2)
    device = PWMOutputDevice(pin)
    device.blink(0.1, 0.1, n=2, background=False)
    pin.assert_states_and_times([
        (0.0, 0),
        (0.0, 1),
        (0.1, 0),
        (0.1, 1),
        (0.1, 0)
        ])
开发者ID:DeeJay,项目名称:python-gpiozero,代码行数:11,代码来源:test_outputs.py

示例12: test_output_pwm_blink_background

def test_output_pwm_blink_background():
    pin = MockPWMPin(2)
    with PWMOutputDevice(pin) as device:
        device.blink(0.1, 0.1, n=2)
        device._blink_thread.join()
        pin.assert_states_and_times([
            (0.0, 0),
            (0.0, 1),
            (0.1, 0),
            (0.1, 1),
            (0.1, 0)
            ])
开发者ID:ChiangFamily,项目名称:python-gpiozero,代码行数:12,代码来源:test_outputs.py

示例13: test_output_pwm_blink_foreground

def test_output_pwm_blink_foreground():
    pin = MockPWMPin(2)
    with PWMOutputDevice(pin) as device:
        start = time()
        device.blink(0.1, 0.1, n=2, background=False)
        assert isclose(time() - start, 0.4, abs_tol=0.05)
        pin.assert_states_and_times([
            (0.0, 0),
            (0.0, 1),
            (0.1, 0),
            (0.1, 1),
            (0.1, 0)
            ])
开发者ID:EdwardBetts,项目名称:python-gpiozero,代码行数:13,代码来源:test_outputs.py

示例14: test_mock_pwm_pin_state

def test_mock_pwm_pin_state():
    pin = MockPWMPin(2)
    with pytest.raises(PinSetInput):
        pin.state = 1
    pin.function = "output"
    assert pin.state == 0
    pin.state = 1
    assert pin.state == 1
    pin.state = 0
    assert pin.state == 0
    pin.state = 0.5
    assert pin.state == 0.5
开发者ID:pcopa,项目名称:python-gpiozero,代码行数:12,代码来源:test_mock_pin.py

示例15: test_output_pwm_write_silly

def test_output_pwm_write_silly():
    pin = MockPWMPin(2)
    with PWMOutputDevice(pin) as device:
        pin.function = 'input'
        with pytest.raises(AttributeError):
            device.off()
开发者ID:EdwardBetts,项目名称:python-gpiozero,代码行数:6,代码来源:test_outputs.py


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