File tree Expand file tree Collapse file tree 4 files changed +51
-0
lines changed Expand file tree Collapse file tree 4 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ # SX1509 I/O Expander
2
+
3
+ See [ MODULES] ( ../MODULES.md ) for other modules and for info about the SX1509
4
+
5
+ Things to know:
6
+ * 3.3V max!
7
+ * I2C address is ` 0x3E ` by default (but might change depending on your breakout board!)
8
+
9
+ ## Schema
10
+
11
+ ![ Schema] ( schema.png )
12
+
13
+ ## Code
14
+
15
+ The code requires 2 libraries
16
+ * Wire (for I2C communication)
17
+ * SparkFunSX1509 for using the SX1509 itself
18
+
Original file line number Diff line number Diff line change
1
+ #include < Arduino.h>
2
+ #include < Wire.h> // Include the I2C library (required)
3
+ #include < SparkFunSX1509.h> // Include SX1509 library
4
+
5
+ SX1509 io; // Create an SX1509 object
6
+
7
+ const int SX1509_BTN_PIN = 0 ;
8
+
9
+ void setup (){
10
+ Serial.begin (9600 );
11
+
12
+ // Try to connect to the i/o expander
13
+ if (!io.begin (0x3E )) {
14
+ Serial.println (" SX1509 not connected" );
15
+ } else {
16
+ Serial.println (" SX1509 connected" );
17
+ }
18
+
19
+ // Configure pin 0 as input
20
+ io.pinMode (SX1509_BTN_PIN, INPUT_PULLUP);
21
+ }
22
+
23
+
24
+ void loop (){
25
+
26
+ // Use io.digitalRead() to check if an SX1509 input I/O is either LOW or HIGH.
27
+ if (io.digitalRead (SX1509_BTN_PIN) == LOW) {
28
+ Serial.println (" I/O Expander button pushed" );
29
+ while (io.digitalRead (SX1509_BTN_PIN) == LOW)
30
+ ; // Wait for button to release (this is blocking the program)
31
+ }
32
+
33
+ }
You can’t perform that action at this time.
0 commit comments