Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* for long time-period reference
- 4,294,967,295 millisecs
- 4,294,967 seconds
- 71,583 minutes
- 1,193 hours
- 50 days
- */
- #define ledPin 5 // LED connected to digital pin 9
- #define ledPin2 4 // LED connected to digital pin 9
- #define toggle 7
- int weldingTable[][2] ={{3,5}, {2, 3}};
- int i, j, count;
- unsigned long offTimeDelay;
- unsigned long onTimeDelay;
- long t1;
- // since it's not being initialized, both dimension must be define explicity
- long delayTable[2][2];
- void setup() {
- pinMode(ledPin, OUTPUT);
- pinMode(ledPin2, OUTPUT);
- pinMode(toggle, INPUT_PULLUP);
- // do time-conversion once to save on repeated multiplications
- for (i=0; i<2; i++) {
- delayTable[i][0] = weldingTable[i][0] * 60000;
- delayTable[i][1] = weldingTable[i][1] * 60000;
- }
- }
- void loop() {
- if (digitalRead(toggle) == LOW) { //begin one major cycle
- for (i=0; i<2; i++) { //assign time periods
- onTimeDelay = delayTable[i][0];
- offTimeDelay = delayTable[i][1];
- 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
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment