1- #include < Adafruit_MCP23008.h>
2- #include < Adafruit_MCP23X08.h>
3- #include < Adafruit_MCP23X17.h>
4- #include < Adafruit_MCP23XXX.h>
51#include < Wire.h>
62#include < EEPROM.h>
73
8- #include < Adafruit_BusIO_Register.h>
9- #include < Adafruit_I2CDevice.h>
10- #include < Adafruit_I2CRegister.h>
11- #include < Adafruit_SPIDevice.h>
12-
13- #include < SPI.h>
14- #include < EtherCard.h>
15-
16- # define InoDescription " RCnano : 29-Mar-2023"
4+ #define SupportEthernet 1 // Requires Ethercard library
5+ #define SupportMCP23017 1 // Requires Adafruit MCP23008 and MCP23017 libraries
6+ #define InoDescription " RCnano : 29-Mar-2023"
177const int16_t InoID = 2903 ; // change to send defaults to eeprom
188int16_t StoredID; // Defaults ID stored in eeprom
199
@@ -26,7 +16,7 @@ struct ModuleConfig
2616 uint8_t IPpart3 = 1 ; // IP address, 3rd octet
2717 uint8_t RelayOnSignal = 0 ; // value that turns on relays
2818 uint8_t FlowOnDirection = 0 ; // sets on value for flow valve or sets motor direction
29- uint8_t UseMCP23017 = 1 ; // 0 use Nano pins for relays, 1 use MCP23017 for relays
19+ uint8_t UseMCP23017 = SupportMCP23017 == 1 ? 1 : 0 ; // 0 use Nano pins for relays, 1 use MCP23017 for relays
3020 uint8_t Relays[16 ];
3121 uint8_t Debounce = 3 ; // minimum ms pin change, base debounce
3222};
@@ -62,6 +52,9 @@ struct SensorConfig
6252
6353SensorConfig Sensor[2 ];
6454
55+ #if SupportEthernet == 1
56+ #include < SPI.h>
57+ #include < EtherCard.h>
6558// If using the ENC28J60 ethernet shield these pins
6659// are used by it and unavailable for relays:
6760// 7,8,10,11,12,13. It also pulls pin D2 high.
@@ -79,6 +72,17 @@ unsigned int DestinationPort = 29999; // Rate Controller listening port
7972byte Ethernet::buffer[300 ]; // udp send and receive buffer
8073bool ENCfound;
8174static byte selectPin = 10 ;
75+ #endif
76+
77+ #if SupportMCP23017 == 1
78+ #include < Adafruit_MCP23008.h>
79+ #include < Adafruit_MCP23X08.h>
80+ #include < Adafruit_MCP23X17.h>
81+ #include < Adafruit_MCP23XXX.h>
82+ #include < Adafruit_BusIO_Register.h>
83+ #include < Adafruit_I2CDevice.h>
84+ #include < Adafruit_I2CRegister.h>
85+ #include < Adafruit_SPIDevice.h>
8286
8387Adafruit_MCP23X17 mcp;
8488
@@ -105,6 +109,8 @@ Adafruit_MCP23X17 mcp;
105109#define Relay15 1
106110#define Relay16 0
107111
112+ #endif
113+
108114const uint16_t LOOP_TIME = 50 ; // in msec = 20hz
109115uint32_t LoopLast = LOOP_TIME ;
110116
@@ -204,16 +210,15 @@ void setup()
204210 if (MDL .SensorCount < 1 ) MDL .SensorCount = 1 ;
205211 if (MDL .SensorCount > 2 ) MDL .SensorCount = 2 ;
206212
213+ #if UseMCP23017 == 1
207214 if (MDL .UseMCP23017 )
208- {
209215 Serial.println (" Using MCP23017 for relays." );
210- }
211216 else
212- {
217+ # endif
213218 Serial.println (" Using Nano pins for relays." );
214- }
215219
216220 Wire.begin ();
221+ #if SupportMCP23017 == 1
217222 if (MDL .UseMCP23017 )
218223 {
219224 // I/O expander on default address 0x20
@@ -262,6 +267,7 @@ void setup()
262267 }
263268 }
264269 else
270+ #endif
265271 {
266272 // Nano pins
267273 for (int i = 0 ; i < 16 ; i++)
@@ -282,6 +288,7 @@ void setup()
282288 attachInterrupt (digitalPinToInterrupt (Sensor[0 ].FlowPin ), ISR0 , FALLING );
283289 attachInterrupt (digitalPinToInterrupt (Sensor[1 ].FlowPin ), ISR1 , FALLING );
284290
291+ #if SupportEthernet == 1
285292 Serial.println (" " );
286293 Serial.println (" Starting Ethernet ..." );
287294
@@ -319,6 +326,7 @@ void setup()
319326 Serial.println (" " );
320327 Serial.println (" Ethernet controller not found." );
321328 }
329+ #endif
322330
323331 Serial.println (" " );
324332 Serial.println (" Finished Setup." );
@@ -358,15 +366,18 @@ void loop()
358366 {
359367 SendLast = millis ();
360368 SendSerial ();
369+ #if SupportEthernet == 1
361370 SendUDPwired ();
371+ #endif
362372 }
363373
374+ #if SupportEthernet == 1
364375 if (ENCfound)
365376 {
366377 // this must be called for ethercard functions to work.
367378 ether.packetLoop (ether.packetReceive ());
368379 }
369-
380+ # endif
370381 ReceiveSerial ();
371382}
372383
0 commit comments