當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。