Forgive the delay but I have spent some time reading the earlier posts regarding “Merging Programs” and have come to the realization that I do not want to merge the programs but rather to run two separate programs in sequence. The programs (Sketches) do not interact with each other. Given the simple tasks I want to use them for I don’t think that any delays in running sequentially would be noticeable. As suggested I have included the two program examples. I have set the hardware up on a breadboard and individually they both work fine.
First Program
// MRH Welder Indirect View with Control Pin
// G. Bunza 2016
//
#define welderpinWH 12 // WHITE LED (Anode/Plus side) attaches to this pin
#define welderpinBL 11 // BLUE LED (Anode/Plus side) attaches to this pin
#define control_pin 14 //Control Pin is Pin 14 (A0) Low/Ground is OFF
// OPEN (Unattachd) Pin is ON
void setup()
{
pinMode(welderpinWH, OUTPUT);
pinMode(welderpinBL, OUTPUT);
digitalWrite(welderpinWH, LOW);
digitalWrite(welderpinBL, LOW);
pinMode (control_pin, INPUT_PULLUP);
}
void loop()
{
int weld_tim;
weld_tim = random (21,45);
if (digitalRead(control_pin) == HIGH) {
for (int i=1; i<= weld_tim; i++) run_welder();
delay (3300);
weld_tim = random (33,75);
for (int i=1; i<= weld_tim; i++) run_welder();
delay(10000+random(4000,9000));
}
}
void run_welder () {
digitalWrite(welderpinWH, HIGH);
digitalWrite(welderpinBL, HIGH);
delay (random (10,120));
digitalWrite(welderpinWH, LOW);
digitalWrite(welderpinBL, HIGH);
delay (random (20,150));
digitalWrite(welderpinWH, HIGH);
digitalWrite(welderpinBL, LOW);
delay (random (30,180));
digitalWrite(welderpinWH, HIGH);
digitalWrite(welderpinBL, LOW);
delay (random (10,114));
digitalWrite(welderpinWH, LOW);
digitalWrite(welderpinBL, HIGH);
delay (random (20,155));
digitalWrite(welderpinWH, HIGH);
digitalWrite(welderpinBL, HIGH);
delay (random (10,140));
digitalWrite(welderpinWH, LOW);
digitalWrite(welderpinBL, LOW);
}
Second Program
// Fire Light with Control Pin
// G. Bunza 2016
//
#define FireRED 12 // RED LED (Anode/Plus side) attaches to this pin
#define FireYEL 11 // YELLOW LED (Anode/Plus side) attaches to this pin
#define FireWHT 10 // WHITE LED (Anode/Plus side) attaches to this pin
#define change_delay 60
int control_pin = 14; //Control Pin is Pin 14 (A0) Low/Ground is OFF
// OPEN (Unattachd) Pin is ON
void setup()
{
pinMode(FireRED, OUTPUT);
pinMode(FireYEL, OUTPUT);
pinMode(FireWHT, OUTPUT);
digitalWrite(FireRED, LOW);
digitalWrite(FireYEL, LOW);
digitalWrite(FireWHT, LOW);
pinMode (control_pin, INPUT_PULLUP);
}
void loop()
{
digitalWrite(FireRED, tvtuning(84));
digitalWrite(FireYEL, tvtuning(77));
digitalWrite(FireWHT, tvtuning(5));
delay (change_delay);
}
byte tvtuning (int time_on) {
if (digitalRead(control_pin) == LOW) return 0; //Eventually all OFF
if (random (0,100)< time_on) return 1; // ON time_on% of the time
else return 0;
}