Hello, I have a rare requirement i.e.
- I have a sketch called Basic and another sketch called Advanced.
- In the basic sketch I am using few pins as I/O to trigger few relays and for different functionality.
- I have another sketch called Advanced, I am using the same pins as I/O for other functionality.
- Now I want to combine both programs as a single sketch and based on one digital pin the program should decide which functionality should execute.
In simple words, if pin2 is connected to GND pin then basic sketch functionality should execute and it pin 2 is open then Advanced sketch functionality should be used.
example basic sketch:
#include <avr/wdt.h>
const int Relay1_PIN = 4;
const int Relay2_PIN = 5;
const int Relay3_PIN = 6;
const int Relay4_PIN = 7;
const int External_INPUT_PIN = 8;
const int Relay1_LED = 9;
const int Relay2_LED = 10;
const int Relay3_LED = 11;
const int Relay4_LED = 12;
const int BLINKLED = 13;
void setup() {
pinMode(Relay1_PIN, OUTPUT);
pinMode(Relay2_PIN, OUTPUT);
pinMode(Relay3_PIN, OUTPUT);
pinMode(Relay4_PIN, OUTPUT);
pinMode(Relay1_LED, OUTPUT);
pinMode(Relay2_LED, OUTPUT);
pinMode(Relay3_LED, OUTPUT);
pinMode(Relay4_LED, OUTPUT);
pinMode(BLINKLED, OUTPUT);
pinMode(External_INPUT_PIN, INPUT_PULLUP);
digitalWrite(Relay1_PIN, HIGH);
digitalWrite(Relay2_PIN, HIGH);
digitalWrite(Relay3_PIN, HIGH);
digitalWrite(Relay4_PIN, HIGH);
digitalWrite(Relay1_LED, LOW);
digitalWrite(Relay2_LED, LOW);
digitalWrite(Relay3_LED, LOW);
digitalWrite(Relay4_LED, LOW);
digitalWrite(BLINKLED, LOW);
}
voild loop(){
## code to control relays ##
}
function mylogic()
{
}
Advanced sketch:
-------------------------
#include <avr/wdt.h>
const int Relay5_PIN = 4;
const int Relay6_PIN = 5;
const int Relay7_PIN = 6;
const int Relay8_PIN = 7;
const int External_INPUT_PIN = 8;
const int Relay5_LED = 9;
const int Relay6_LED = 10;
const int Relay7_LED = 11;
const int Relay8_LED = 12;
const int BLINKLED = 13;
void setup() {
pinMode(Relay5_PIN, OUTPUT);
pinMode(Relay6_PIN, OUTPUT);
pinMode(Relay7_PIN, OUTPUT);
pinMode(Relay8_PIN, OUTPUT);
pinMode(Relay5_LED, OUTPUT);
pinMode(Relay6_LED, OUTPUT);
pinMode(Relay7_LED, OUTPUT);
pinMode(Relay8_LED, OUTPUT);
pinMode(BLINKLED, OUTPUT);
pinMode(External_INPUT_PIN, INPUT_PULLUP);
digitalWrite(Relay5_PIN, HIGH);
digitalWrite(Relay6_PIN, HIGH);
digitalWrite(Relay7_PIN, HIGH);
digitalWrite(Relay8_PIN, HIGH);
digitalWrite(Relay5_LED, LOW);
digitalWrite(Relay6_LED, LOW);
digitalWrite(Relay7_LED, LOW);
digitalWrite(Relay8_LED, LOW);
digitalWrite(BLINKLED, LOW);
}
void loop(){
## code to control relays ##
}
function test(){
}
function two(){
}
I tried to club but not getting how to use same pins for different functionalities. Can anyone help me on this?