Skip to content

Commit ff8a675

Browse files
committed
Adding comments to src and example.
1 parent d5418a2 commit ff8a675

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

examples/Example1-DigitalOutput/Example1-DigitalOutput.ino

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Date: May 4, 2018
66
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
77
Feel like supporting our work? Buy a board from SparkFun!
8-
https://www.sparkfun.com/products/TODO
8+
https://www.sparkfun.com/products/14733
99
This example demonstrates how to use pinMode and digitalWrite/write to set output values of the PCA9536
1010
1111
Hardware Connections:
@@ -19,17 +19,19 @@
1919
PCA9536 io;
2020

2121
void setup() {
22+
// Initialize the PCA9536 with a begin function
2223
io.begin();
23-
for (int i = 0; i < 4; i++)
24-
{
24+
for (int i = 0; i < 4; i++) {
25+
// pinMode can be used to set an I/O as OUTPUT or INPUT
2526
io.pinMode(i, OUTPUT);
2627
}
2728
}
2829

2930
void loop() {
30-
for (int i = 3; i >= 0; i--)
31-
{
32-
io.write((i+1)%4, HIGH); // Turn last pin HIGH
31+
for (int i = 3; i >= 0; i--) {
32+
// digitalWrite or write can be used to set an I/O value
33+
// (both perform the same function)
34+
io.digitalWrite((i+1)%4, HIGH); // Turn last pin HIGH
3335
io.write(i, LOW); // Turn this pin LOW
3436
delay(1000);
3537
}

src/SparkFun_PCA9536_Arduino_Library.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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.
@@ -40,6 +40,15 @@ PCA9536::PCA9536()
4040
_deviceAddress = PCA9536_ADDRESS_INVALID;
4141
}
4242

43+
boolean PCA9536::begin(void)
44+
{
45+
if (begin(Wire) == PCA9536_ERROR_SUCCESS)
46+
{
47+
return true;
48+
}
49+
return false;
50+
}
51+
4352
PCA9536_error_t PCA9536::begin(TwoWire &wirePort)
4453
{
4554
uint8_t systemControl = 0;

src/SparkFun_PCA9536_Arduino_Library.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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.
@@ -33,11 +33,13 @@
3333

3434
#include <Wire.h>
3535

36+
// Valid PCA9536 addresses
3637
typedef enum {
3738
PCA9536_ADDRESS = 0x41,
3839
PCA9536_ADDRESS_INVALID = 0xFF
3940
} PCA9536_Address_t;
4041

42+
// PCA9536 registers:
4143
typedef 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:
4952
typedef enum {
5053
PCA9536_ERROR_READ = -4,
5154
PCA9536_ERROR_WRITE = -3,
@@ -55,6 +58,7 @@ typedef enum {
5558
} PCA9536_error_t;
5659
const PCA9536_error_t PCA9536_SUCCESS = PCA9536_ERROR_SUCCESS;
5760

61+
// PCA9536 invert/normal values:
5862
typedef enum {
5963
PCA9536_RETAIN,
6064
PCA9536_INVERT,
@@ -73,18 +77,26 @@ class PCA9536 {
7377
public:
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

Comments
 (0)