Skip to content

Commit fb2f281

Browse files
committed
Updated value, docs, example
1 parent e0e6723 commit fb2f281

File tree

4 files changed

+48
-16
lines changed

4 files changed

+48
-16
lines changed

README.rst

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Introduction
1313
:target: https://travis-ci.org/adafruit/Adafruit_CircuitPython_74HC595
1414
:alt: Build Status
1515

16-
.. todo:: Describe what the library does.
16+
CircuitPython driver for 74HC595 shift register.
1717

1818
Dependencies
1919
=============
@@ -29,7 +29,26 @@ This is easily achieved by downloading
2929
Usage Example
3030
=============
3131

32-
.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst.
32+
.. code-block:: python
33+
34+
import board
35+
import adafruit_74hc595
36+
import busio
37+
import digitalio
38+
import time
39+
40+
spi = busio.SPI(board.SCK, MOSI=board.MOSI)
41+
42+
latch_pin = digitalio.DigitalInOut(board.D5)
43+
sr = adafruit_74hc595.ShiftRegister74HC595(spi, latch_pin)
44+
45+
pin1 = sr.get_pin(1)
46+
47+
while True:
48+
pin1.value = True
49+
time.sleep(1)
50+
pin1.value = False
51+
time.sleep(1)
3352
3453
Contributing
3554
============

adafruit_74hc595.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222
"""
23-
`Adafruit_74HC595`
23+
`adafruit_74hc595`
2424
====================================================
2525
2626
CircuitPython driver for 74HC595 shift register.
@@ -53,7 +53,7 @@
5353

5454
class DigitalInOut:
5555
"""Digital input/output of the 74HC595. The interface is exactly the
56-
same as the digitalio.DigitalInOut class, however note that by design
56+
same as the ``digitalio.DigitalInOut`` class, however note that by design
5757
this device is OUTPUT ONLY! Attempting to read inputs or set
5858
direction as input will raise an exception.
5959
"""
@@ -71,23 +71,22 @@ def __init__(self, pin_number, shift_register_74hc595):
7171
# in this case.
7272
# pylint: disable=unused-argument
7373
def switch_to_output(self, value=False, **kwargs):
74-
"""DigitalInOut switch_to_output"""
74+
"""``DigitalInOut switch_to_output``"""
7575
self.direction = digitalio.Direction.OUTPUT
7676
self.value = value
7777

7878
def switch_to_input(self, **kwargs): # pylint: disable=no-self-use
79-
"""Do not call switch_to_input"""
79+
"""``switch_to_input`` is not supported."""
8080
raise RuntimeError('Digital input not supported.')
8181
# pylint: enable=unused-argument
8282

8383
@property
8484
def value(self):
85-
"""Do not call value"""
86-
raise RuntimeError('Digital input not supported.')
85+
"""The value of the pin, either True for high or False for low."""
86+
return self._shift_register.gpio & (1 << self._pin) == (1 << self._pin)
8787

8888
@value.setter
8989
def value(self, val):
90-
# Only supported operation, writing a digital output.
9190
gpio = self._shift_register.gpio
9291
if val:
9392
gpio |= (1 << self._pin)
@@ -97,12 +96,12 @@ def value(self, val):
9796

9897
@property
9998
def direction(self):
100-
"""ALWAYS an output!"""
99+
"""``Direction`` can only be set to ``OUTPUT``."""
101100
return digitalio.Direction.OUTPUT
102101

103102
@direction.setter
104103
def direction(self, val): # pylint: disable=no-self-use
105-
"""Can only be set as OUTPUT!"""
104+
"""``Direction`` can only be set to ``OUTPUT``."""
106105
if val != digitalio.Direction.OUTPUT:
107106
raise RuntimeError('Digital input not supported.')
108107

docs/index.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26-
.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave
27-
the toctree above for use later.
28-
2926
.. toctree::
3027
:caption: Related Products
3128

32-
.. todo:: Add any product links here. If there are none, then simply delete this todo and leave
33-
the toctree above for use later.
29+
74HC595 Shift Register - 3 pack <https://www.adafruit.com/product/450>
3430

3531
.. toctree::
3632
:caption: Other Links

examples/74hc595_simpletest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import time
2+
import board
3+
import busio
4+
import digitalio
5+
import adafruit_74hc595
6+
7+
spi = busio.SPI(board.SCK, MOSI=board.MOSI)
8+
9+
latch_pin = digitalio.DigitalInOut(board.D5)
10+
sr = adafruit_74hc595.ShiftRegister74HC595(spi, latch_pin)
11+
12+
pin1 = sr.get_pin(1)
13+
14+
while True:
15+
pin1.value = True
16+
time.sleep(1)
17+
pin1.value = False
18+
time.sleep(1)

0 commit comments

Comments
 (0)