本文整理汇总了Python中gpiozero.pins.mock.MockPin.state方法的典型用法代码示例。如果您正苦于以下问题:Python MockPin.state方法的具体用法?Python MockPin.state怎么用?Python MockPin.state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gpiozero.pins.mock.MockPin
的用法示例。
在下文中一共展示了MockPin.state方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_led_bar_graph_value
# 需要导入模块: from gpiozero.pins.mock import MockPin [as 别名]
# 或者: from gpiozero.pins.mock.MockPin import state [as 别名]
def test_led_bar_graph_value():
pin1 = MockPin(2)
pin2 = MockPin(3)
pin3 = MockPin(4)
with LEDBarGraph(pin1, pin2, pin3) as graph:
assert isinstance(graph[0], LED)
assert isinstance(graph[1], LED)
assert isinstance(graph[2], LED)
assert graph.active_high
assert graph[0].active_high
assert graph[1].active_high
assert graph[2].active_high
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)
pin1.state = True
pin2.state = True
assert graph.value == 1
pin3.state = False
assert graph.value == 2/3
pin3.state = True
pin1.state = False
assert graph.value == -2/3
示例2: test_mock_pin_state
# 需要导入模块: from gpiozero.pins.mock import MockPin [as 别名]
# 或者: from gpiozero.pins.mock.MockPin import state [as 别名]
def test_mock_pin_state():
pin = MockPin(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 == 1
示例3: test_led_bar_graph_value
# 需要导入模块: from gpiozero.pins.mock import MockPin [as 别名]
# 或者: from gpiozero.pins.mock.MockPin import state [as 别名]
def test_led_bar_graph_value():
pin1 = MockPin(2)
pin2 = MockPin(3)
pin3 = MockPin(4)
with LEDBarGraph(pin1, pin2, pin3) as graph:
graph.value = 0
assert not any((pin1.state, pin2.state, pin3.state))
graph.value = 1
assert all((pin1.state, pin2.state, pin3.state))
graph.value = 1/3
assert pin1.state and not (pin2.state or pin3.state)
graph.value = -1/3
assert pin3.state and not (pin1.state or pin2.state)
pin1.state = True
pin2.state = True
assert graph.value == 1
pin3.state = False
assert graph.value == 2/3
pin3.state = True
pin1.state = False
assert graph.value == -2/3