Skip to content

Commit 83aecd4

Browse files
author
Sylvan Butler
committed
create input_pins() to read multiple pins with one call - MCP230xx
1 parent eed9159 commit 83aecd4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Adafruit_GPIO/MCP230xx.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,18 @@ def input(self, pin):
100100
"""Read the specified pin and return GPIO.HIGH/True if the pin is pulled
101101
high, or GPIO.LOW/False if pulled low.
102102
"""
103-
self._validate_pin(pin)
103+
return self.input_pins([pin])[0]
104+
105+
def input_pins(self, pins):
106+
"""Read multiple pins specified in the given list and return list of pin values
107+
GPIO.HIGH/True if the pin is pulled high, or GPIO.LOW/False if pulled low.
108+
"""
109+
for pin in pins:
110+
self._validate_pin(pin)
104111
# Get GPIO state.
105112
gpio = self._device.readList(self.GPIO, self.gpio_bytes)
106113
# Return True if pin's bit is set.
107-
return (gpio[int(pin/8)] & 1 << (int(pin%8))) > 0
114+
return [(gpio[int(pin/8)] & 1 << (int(pin%8))) > 0 for pin in pins]
108115

109116
def pullup(self, pin, enabled):
110117
"""Turn on the pull-up resistor for the specified pin if enabled is True,

0 commit comments

Comments
 (0)