22 This is a library written for the PCA9536 4-bit I2C I/O Expander
33 SparkFun sells these at its website: www.sparkfun.com
44 Do you like this library? Help support SparkFun. Buy a board!
5- https://www.sparkfun.com/products/TODO
5+ https://www.sparkfun.com/products/14733
66 Written by Jim Lindblom @ SparkFun Electronics, May 4th, 2018
77 The PCA9536 is a 4-bit I/O digital expander, which communicates via an I2C bus.
88 The expander can read or write four separate I/O.
3333
3434#include < Wire.h>
3535
36+ // Valid PCA9536 addresses
3637typedef enum {
3738 PCA9536_ADDRESS = 0x41 ,
3839 PCA9536_ADDRESS_INVALID = 0xFF
3940} PCA9536_Address_t;
4041
42+ // PCA9536 registers:
4143typedef enum {
4244 PCA9536_REGISTER_INPUT_PORT = 0x00 ,
4345 PCA9536_REGISTER_OUTPUT_PORT = 0x01 ,
@@ -46,6 +48,7 @@ typedef enum {
4648 PCA9536_REGISTER_INVALID
4749} PCA9536_REGISTER_t;
4850
51+ // PCA9536 error code returns:
4952typedef enum {
5053 PCA9536_ERROR_READ = -4 ,
5154 PCA9536_ERROR_WRITE = -3 ,
@@ -55,6 +58,7 @@ typedef enum {
5558} PCA9536_error_t;
5659const PCA9536_error_t PCA9536_SUCCESS = PCA9536_ERROR_SUCCESS;
5760
61+ // PCA9536 invert/normal values:
5862typedef enum {
5963 PCA9536_RETAIN,
6064 PCA9536_INVERT,
@@ -73,18 +77,26 @@ class PCA9536 {
7377public:
7478 PCA9536 ();
7579
76- PCA9536_error_t begin (TwoWire &wirePort = Wire);
80+ // begin initializes the Wire port and I/O expander
81+ boolean begin (void );
82+ // give begin a TwoWire port to specify the I2C port
83+ PCA9536_error_t begin (TwoWire &wirePort);
7784
85+ // setDebugStream to enable library debug statements
7886 void setDebugStream (Stream &debugPort = Serial);
7987
88+ // pinMode can set a pin (0-3) to INPUT or OUTPUT
8089 PCA9536_error_t pinMode (uint8_t pin, uint8_t mode);
8190
91+ // digitalWrite and write can be used to set a pin HIGH or LOW
8292 PCA9536_error_t digitalWrite (uint8_t pin, uint8_t value);
8393 PCA9536_error_t write (uint8_t pin, uint8_t value);
8494
95+ // digitalRead and read can be used to read a pin (0-3)
8596 uint8_t digitalRead (uint8_t pin);
8697 uint8_t read (uint8_t pin);
8798
99+ // invert and revert can be used to invert (or not) the I/O logic during a read
88100 PCA9536_error_t invert (uint8_t pin, PCA9536_invert_t inversion = PCA9536_INVERT);
89101 PCA9536_error_t revert (uint8_t pin);
90102
0 commit comments