/* collaboratino welder for long time-period reference with changed toggle to A0 from d7
4,294,967,295 millisecs
4,294,967 seconds
71,583 minutes
1,193 hours
50 days
*/
#define ledPin 5
#define ledPin2 4
#define ledPin3 2
#define ledPin4 3
#define toggle A0
int weldingTable[][2] = {{3, 5}, {2, 3}};
int weldingTable2[][2] = {{1, 2}, {1, 3}};
int i, j, count;
unsigned long offTimeDelay;
unsigned long onTimeDelay;
unsigned long offTimeDelay2;
unsigned long onTimeDelay2;
unsigned long t1;
// since it's not being initialized, both dimension must be define explicity
long delayTable[2][2];
long delayTable2[2][2];
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(toggle, INPUT);
// do time-conversion once to save on repeated multiplications
for (i = 0; i < 2; i++) {
delayTable[i][0] = weldingTable[i][0] * 6000;
delayTable[i][1] = weldingTable[i][1] * 6000;
delayTable2[i][0] = weldingTable[i][0] * 6000;
delayTable2[i][1] = weldingTable[i][1] * 6000;
}
}
void loop() {
if (digitalRead(toggle) == LOW) { //begin one major cycle
Serial.println(toggle);
for (i = 0; i < 2; i++) { //assign time periods
onTimeDelay = delayTable[i][0];
Serial.println(onTimeDelay);
offTimeDelay = delayTable[i][1];
Serial.println(offTimeDelay);
t1 = millis(); //start timing the 'on' period
while ((millis() - t1) < onTimeDelay) { //while 'on' time hasn't run out
// but if user wants 'out', begin breaking out here
if (digitalRead(toggle) != LOW) break;
////setup a random amount of flashing and do the flashing
count = random(10, 80);
for (j = 0; j < count; j++) {
digitalWrite(ledPin, HIGH); // flash one LED
delay(random(50));
digitalWrite(ledPin2, HIGH); // and then the other
delay(random(20));
digitalWrite(ledPin, LOW); // then turn them both off
digitalWrite(ledPin2, LOW);
delay(random(200)); // brief pause
}
delay(random(800, 2000)); //pause before resume flashing
}
// 'on' time has run out, so reset timer and begin the 'off' time cycle
t1 = millis();
while ((millis() - t1) < offTimeDelay) {
// and complete breaking out of process here
if (digitalRead(toggle) != LOW) break;
}
// 'off' time is done, so go back and do it again for the second set of time periods
}
// both time periods have been completed, check and see if user wants to do it all over again
}
//***********************************************
//welder 2
for (i = 0; i < 2; i++) { //assign time periods
onTimeDelay2 = delayTable2[i][0];
Serial.println(onTimeDelay2);
offTimeDelay2 = delayTable2[i][1];
Serial.println(offTimeDelay2);
t1 = millis(); //start timing the 'on' period
while ((millis() - t1) < onTimeDelay2) { //while 'on' time hasn't run out
// but if user wants 'out', begin breaking out here
if (digitalRead(toggle) != LOW) break;
////setup a random amount of flashing and do the flashing
count = random(10, 80);
for (j = 0; j < count; j++) {
digitalWrite(ledPin3, HIGH); // flash one LED
delay(random(50));
digitalWrite(ledPin4, HIGH); // and then the other
delay(random(20));
digitalWrite(ledPin3, LOW); // then turn them both off
digitalWrite(ledPin4, LOW);
delay(random(200)); // brief pause
}
delay(random(400, 800)); //pause before resume flashing
}
// 'on' time has run out, so reset timer and begin the 'off' time cycle
t1 = millis();
while ((millis() - t1) < offTimeDelay2) {
// and complete breaking out of process here
if (digitalRead(toggle) != LOW) break;
}
// 'off' time is done, so go back and do it again for the second set of time periods
}
// both time periods have been completed, check and see if user wants to do it all over again
}