18
18
19
19
bool ArduinoIOExpanderClass::begin ()
20
20
{
21
- Wire.begin ();
22
- _tca.initialize ();
21
+ if (!_tca.testConnection ()) {
22
+ return false ;
23
+ }
24
+ // Initialize all pins to the default mode
25
+ initPins ();
26
+
27
+ return true ;
28
+ }
29
+
30
+ bool ArduinoIOExpanderClass::begin (uint8_t address)
31
+ {
32
+ setAddress (address);
23
33
if (!_tca.testConnection ()) {
24
34
return false ;
25
35
}
@@ -43,6 +53,10 @@ bool ArduinoIOExpanderClass::pinMode(int pin, PinMode direction)
43
53
return true ;
44
54
}
45
55
56
+ void ArduinoIOExpanderClass::setAddress (uint8_t address) {
57
+ _tca.setAddress (address);
58
+ }
59
+
46
60
bool ArduinoIOExpanderClass::set (int pin, PinStatus status)
47
61
{
48
62
if (pin < IO_READ_CH_PIN_00) {
@@ -57,52 +71,70 @@ bool ArduinoIOExpanderClass::set(int pin, PinStatus status)
57
71
58
72
int ArduinoIOExpanderClass::read (int pin)
59
73
{
60
- if (pin > IO_READ_CH_PIN_11) {
61
- return _tca.readPin (pin) == true ? 1 : 0 ;
74
+ if (_tca.getAddress () == IO_ADD) {
75
+ if (pin > TCA6424A_P13 && pin <= TCA6424A_P27) {
76
+ return _tca.readPin (pin) == true ? 1 : 0 ;
77
+ }
78
+ } else if (_tca.getAddress () == DIN_ADD) {
79
+ if ((pin >= TCA6424A_P00) && (pin <= TCA6424A_P10) && (pin !=TCA6424A_P03)) {
80
+ return _tca.readPin (pin) == true ? 1 : 0 ;
81
+ }
62
82
}
63
83
return -1 ;
64
84
}
65
85
66
86
void ArduinoIOExpanderClass::initPins ()
67
87
{
68
- PinStatus status = SWITCH_OFF;
69
- pinMode (IO_WRITE_CH_PIN_00, OUTPUT);
70
- pinMode (IO_WRITE_CH_PIN_01, OUTPUT);
71
- pinMode (IO_WRITE_CH_PIN_02, OUTPUT);
72
- pinMode (IO_WRITE_CH_PIN_03, OUTPUT);
73
- pinMode (IO_WRITE_CH_PIN_04, OUTPUT);
74
- pinMode (IO_WRITE_CH_PIN_05, OUTPUT);
75
- pinMode (IO_WRITE_CH_PIN_06, OUTPUT);
76
- pinMode (IO_WRITE_CH_PIN_07, OUTPUT);
77
- pinMode (IO_WRITE_CH_PIN_08, OUTPUT);
78
- pinMode (IO_WRITE_CH_PIN_09, OUTPUT);
79
- pinMode (IO_WRITE_CH_PIN_10, OUTPUT);
80
- pinMode (IO_WRITE_CH_PIN_11, OUTPUT);
81
- pinMode (IO_READ_CH_PIN_00, INPUT);
82
- pinMode (IO_READ_CH_PIN_01, INPUT);
83
- pinMode (IO_READ_CH_PIN_02, INPUT);
84
- pinMode (IO_READ_CH_PIN_03, INPUT);
85
- pinMode (IO_READ_CH_PIN_04, INPUT);
86
- pinMode (IO_READ_CH_PIN_05, INPUT);
87
- pinMode (IO_READ_CH_PIN_06, INPUT);
88
- pinMode (IO_READ_CH_PIN_07, INPUT);
89
- pinMode (IO_READ_CH_PIN_08, INPUT);
90
- pinMode (IO_READ_CH_PIN_09, INPUT);
91
- pinMode (IO_READ_CH_PIN_10, INPUT);
92
- pinMode (IO_READ_CH_PIN_11, INPUT);
93
-
94
- set (IO_WRITE_CH_PIN_00, status);
95
- set (IO_WRITE_CH_PIN_01, status);
96
- set (IO_WRITE_CH_PIN_02, status);
97
- set (IO_WRITE_CH_PIN_03, status);
98
- set (IO_WRITE_CH_PIN_04, status);
99
- set (IO_WRITE_CH_PIN_05, status);
100
- set (IO_WRITE_CH_PIN_06, status);
101
- set (IO_WRITE_CH_PIN_07, status);
102
- set (IO_WRITE_CH_PIN_08, status);
103
- set (IO_WRITE_CH_PIN_09, status);
104
- set (IO_WRITE_CH_PIN_10, status);
105
- set (IO_WRITE_CH_PIN_11, status);
88
+
89
+ if (_tca.getAddress () == IO_ADD) {
90
+ PinStatus status = SWITCH_OFF;
91
+ pinMode (IO_WRITE_CH_PIN_00, OUTPUT);
92
+ pinMode (IO_WRITE_CH_PIN_01, OUTPUT);
93
+ pinMode (IO_WRITE_CH_PIN_02, OUTPUT);
94
+ pinMode (IO_WRITE_CH_PIN_03, OUTPUT);
95
+ pinMode (IO_WRITE_CH_PIN_04, OUTPUT);
96
+ pinMode (IO_WRITE_CH_PIN_05, OUTPUT);
97
+ pinMode (IO_WRITE_CH_PIN_06, OUTPUT);
98
+ pinMode (IO_WRITE_CH_PIN_07, OUTPUT);
99
+ pinMode (IO_WRITE_CH_PIN_08, OUTPUT);
100
+ pinMode (IO_WRITE_CH_PIN_09, OUTPUT);
101
+ pinMode (IO_WRITE_CH_PIN_10, OUTPUT);
102
+ pinMode (IO_WRITE_CH_PIN_11, OUTPUT);
103
+ pinMode (IO_READ_CH_PIN_00, INPUT);
104
+ pinMode (IO_READ_CH_PIN_01, INPUT);
105
+ pinMode (IO_READ_CH_PIN_02, INPUT);
106
+ pinMode (IO_READ_CH_PIN_03, INPUT);
107
+ pinMode (IO_READ_CH_PIN_04, INPUT);
108
+ pinMode (IO_READ_CH_PIN_05, INPUT);
109
+ pinMode (IO_READ_CH_PIN_06, INPUT);
110
+ pinMode (IO_READ_CH_PIN_07, INPUT);
111
+ pinMode (IO_READ_CH_PIN_08, INPUT);
112
+ pinMode (IO_READ_CH_PIN_09, INPUT);
113
+ pinMode (IO_READ_CH_PIN_10, INPUT);
114
+ pinMode (IO_READ_CH_PIN_11, INPUT);
115
+
116
+ set (IO_WRITE_CH_PIN_00, status);
117
+ set (IO_WRITE_CH_PIN_01, status);
118
+ set (IO_WRITE_CH_PIN_02, status);
119
+ set (IO_WRITE_CH_PIN_03, status);
120
+ set (IO_WRITE_CH_PIN_04, status);
121
+ set (IO_WRITE_CH_PIN_05, status);
122
+ set (IO_WRITE_CH_PIN_06, status);
123
+ set (IO_WRITE_CH_PIN_07, status);
124
+ set (IO_WRITE_CH_PIN_08, status);
125
+ set (IO_WRITE_CH_PIN_09, status);
126
+ set (IO_WRITE_CH_PIN_10, status);
127
+ set (IO_WRITE_CH_PIN_11, status);
128
+ } else {
129
+ pinMode (DIN_READ_CH_PIN_00, INPUT);
130
+ pinMode (DIN_READ_CH_PIN_01, INPUT);
131
+ pinMode (DIN_READ_CH_PIN_02, INPUT);
132
+ pinMode (DIN_READ_CH_PIN_03, INPUT);
133
+ pinMode (DIN_READ_CH_PIN_04, INPUT);
134
+ pinMode (DIN_READ_CH_PIN_05, INPUT);
135
+ pinMode (DIN_READ_CH_PIN_06, INPUT);
136
+ pinMode (DIN_READ_CH_PIN_07, INPUT);
137
+ }
106
138
}
107
139
108
140
ArduinoIOExpanderClass Expander;
0 commit comments