@@ -105,16 +105,22 @@ void SX1509::reset(bool hardware)
105
105
}
106
106
}
107
107
108
- void SX1509::pinDir (byte pin, byte inOut)
108
+ void SX1509::pinDir (byte pin, byte inOut, byte initialLevel )
109
109
{
110
110
// The SX1509 RegDir registers: REG_DIR_B, REG_DIR_A
111
111
// 0: IO is configured as an output
112
112
// 1: IO is configured as an input
113
113
byte modeBit;
114
- if ((inOut == OUTPUT) || (inOut == ANALOG_OUTPUT))
115
- modeBit = 0 ;
116
- else
114
+ if ((inOut == OUTPUT) || (inOut == ANALOG_OUTPUT)) {
115
+ unsigned int tempRegData = readWord (REG_DATA_B);
116
+ if (initialLevel == LOW) {
117
+ tempRegData &= ~(1 <<pin);
118
+ writeWord (REG_DATA_B, tempRegData);
119
+ }
120
+ modeBit = 0 ;
121
+ } else {
117
122
modeBit = 1 ;
123
+ }
118
124
119
125
unsigned int tempRegDir = readWord (REG_DIR_B);
120
126
if (modeBit)
@@ -134,9 +140,9 @@ void SX1509::pinDir(byte pin, byte inOut)
134
140
}
135
141
}
136
142
137
- void SX1509::pinMode (byte pin, byte inOut)
143
+ void SX1509::pinMode (byte pin, byte inOut, byte initialLevel )
138
144
{
139
- pinDir (pin, inOut);
145
+ pinDir (pin, inOut, initialLevel );
140
146
}
141
147
142
148
void SX1509::writePin (byte pin, byte highLow)
@@ -737,8 +743,6 @@ unsigned int SX1509::readWord(byte registerAddress)
737
743
// - No return value.
738
744
void SX1509::readBytes (byte firstRegisterAddress, byte * destination, byte length)
739
745
{
740
- byte readValue;
741
-
742
746
Wire.beginTransmission (deviceAddress);
743
747
Wire.write (firstRegisterAddress);
744
748
Wire.endTransmission ();
0 commit comments