Hi there,
I’m having trouble with the SX1509 library disagreeing with a very strange part of my code.
After a for loop which contains pinMode and digitalWrite on on-board io pins, at the execution of io.digitalWrite for any pin on the SX1509 BOB, the SX1509 pin does not change state and the program does not advance to the next line.
This is part of a larger project, but I have paired it down to this and the error is still reproducible. (I decided to leave the #define in there in case they were useful but I omitted irrelevant variable declarations, some parts of setup() and much of loop()). On my hardware, there is an LED connected to all 16 SX1509 pins in a common anode configuration.
If I turn off lines 79, 80, and 81 (put // in front), everything is fine. But when at least one of those 3 lines is on, again, the program will not advance past line 83. It’s so wierd! Also, I never have any other trouble with the hardware or software for any other reason, although this particular issue has happened several times before. Any help or advice would be appreciated!!
#include <Wire.h>
#include <SparkFunSX1509.h>
const byte SX1509_ADDRESS = 0x3E;
SX1509 io;
#define X1 7
#define X2 6
#define X3 5
#define X4 100
#define X5 100
#define X6 100
#define X7 100
#define X8 100
byte X[9] = {100, X1, X2, X3, X4, X5, X6, X7, X8};
#define Y1 4
#define Y2 3
#define Y3 2
#define Y4 100
#define Y5 100
#define Y6 100
#define Y7 100
#define Y8 100
byte Y[9] = {100, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8};
#define S1 12
#define S2 11
#define S3 10
#define S4 9
#define S5 8
#define S6 100
#define S7 100
byte S[9] = {100, S1, S1, S1, S1, S2, S3, S4, S5};
#define B1 A0
#define B2 A1
#define B3 A2
#define B4 A3
#define L1X 0
#define L2X 1
#define L3X 2
#define L4X 3
#define L5X 4
#define L6X 5
#define L7X 6
#define L8X 7
byte LX[9] = {100, L1X, L2X, L3X, L4X, L5X, L6X, L7X, L8X};
#define L1Y 8
#define L2Y 9
#define L3Y 10
#define L4Y 11
#define L5Y 12
#define L6Y 13
#define L7Y 14
#define L8Y 15
byte LY[9] = {100, L1Y, L2Y, L3Y, L4Y, L5Y, L6Y, L7Y, L8Y};
bool autoMode = 0;
void setup() {
//SX1509 setup
if (!io.begin(SX1509_ADDRESS)) {
while (1);
}
for (int i = 0; i <= 15; i++) {
io.pinMode(i, OUTPUT);
io.digitalWrite(i, HIGH);
}
}
/*77*/ void loop() {
/*78*/ for (int i = 1; i <= 8; i++) {
/*79*/ pinMode(Y[i], INPUT_PULLUP);
/*80*/ pinMode(X[i], OUTPUT);
/*81*/ digitalWrite(X[i], HIGH);
/*82*/ }
/*83*/ io.digitalWrite(5, LOW);
/*84*/
/*85*/}