Skip to content

Commit 3fe972b

Browse files
committed
feat: added examples
1 parent f769d0d commit 3fe972b

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

README.rst

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,26 @@ Or the following command to update an existing version:
6565
Usage Example
6666
=============
6767

68-
.. todo:: Add a quick, simple example. It and other examples should live in the
69-
examples folder and be included in docs/examples.rst.
68+
.. code-block:: python
69+
70+
import board
71+
72+
from gpio_expander import PCA9555, PCA9534
73+
74+
#######################
75+
# 16 bit I2C expander #
76+
#######################
77+
_pca9555 = PCA9555(board.I2C(), 0x20)
78+
79+
# print input 0 bit 0 value; datasheet bit field's name has underscore in place of dot for 16 bit expander
80+
print(_pca9555.I0_0)
81+
82+
# configure an output port and set its value
83+
_pca9555.C1_3 = 0
84+
_pca9555.O1_3 = 0
85+
86+
# print entire configuration registry
87+
print(_pca9555.configuration_ports)
7088
7189
Documentation
7290
=============
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,40 @@
1+
"""Simple tests."""
2+
13
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
24
# SPDX-FileCopyrightText: Copyright (c) 2022 Gabriele Pongelli
35
#
46
# SPDX-License-Identifier: Unlicense
7+
8+
import board
9+
10+
from gpio_expander import PCA9534, PCA9555
11+
12+
#######################
13+
# 16 bit I2C expander #
14+
#######################
15+
_pca9555 = PCA9555(board.I2C(), 0x20)
16+
17+
# print input 0 bit 0 value; datasheet bit field's name has underscore in place of dot for 16 bit expander
18+
print(_pca9555.I0_0) # pylint: disable=no-member
19+
20+
# configure an output port and set its value
21+
_pca9555.C1_3 = 0
22+
_pca9555.O1_3 = 0
23+
24+
# print entire configuration registry
25+
print(_pca9555.configuration_ports) # pylint: disable=no-member
26+
27+
######################
28+
# 8 bit I2C expander #
29+
######################
30+
_pca9534 = PCA9534(board.I2C(), 0x30)
31+
32+
# print input 0 bit value
33+
print(_pca9534.I0) # pylint: disable=no-member
34+
35+
# configure an output port and set its value
36+
_pca9555.C3 = 0 # pylint: disable=invalid-name
37+
_pca9555.O3 = 0 # pylint: disable=invalid-name
38+
39+
# print entire configuration registry
40+
print(_pca9534.configuration_ports) # pylint: disable=no-member

0 commit comments

Comments
 (0)