element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Delay vs Timer
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 15 replies
  • Subscribers 388 subscribers
  • Views 2750 views
  • Users 0 members are here
  • code
  • arduino
Related

Delay vs Timer

WumblingBorkeys
WumblingBorkeys over 3 years ago

I'm making a laser maze for an event, and I've been trying to work this out in my head...

void section1()
{
  delay(100);// delay to make sure it's a real trigger
  laserstate1 = digitalRead(lasersens1);
  if(laserstate1 == 1)// if it is a trigger, if it isn't make sure the lights are off and go back to the loop
  {
  leds[0] = CRGB (255,255,255);
  leds[1] = CRGB (255,255,255);
  leds[2] = CRGB (255,255,255);//Trigger lights to illuminate those who tripped it
  leds[3] = CRGB (255,255,255);
  leds[4] = CRGB (255,255,255);
  FastLED.show();
  
    //resetButtonState = digitalRead(resetButton);
    while(digitalRead(resetButton) == 0 ||  digitalRead(lasersens1) == 1) {//require the person to leave then press a button to reset the lights
    //resetButtonState = digitalRead(resetButton);

    }

  }
  
  leds[0] = CRGB (0,0,0);
  leds[1] = CRGB (0,0,0);
  leds[2] = CRGB (0,0,0);
  leds[3] = CRGB (0,0,0);
  leds[4] = CRGB (0,0,0);
  FastLED.show(); 

}

void loop() {
    while (1)
    {
        laserstate1 = digitalRead(lasersens1);//Wait for a laser to be blocked
        if(laserstate1 == 1)
            {
            section1(); //Trigger the section sequence
            }
  
        }
  
    }

There would be more lasers, hoping to be in the neighborhood of 10-20

My question is would there be an advantage to running a timer instead of the delay in "section1"?

I know there theoretically there would be but when it's only 100ms it doesn't feel necessary.

It should be noted that each lasersens wouldn't trip its own section but rather a group of "lasersens" would make a section, and each trigger a singular set of lights.

The only other thing would be an addition of a kill switch they could find and press to deactivate the system. for x amount of time.

  • Sign in to reply
  • Cancel

Top Replies

  • fmilburn
    fmilburn over 3 years ago +7
    Hi WumblingBorkeys , In general it isn't considered good practice to use delays like this and a non-blocking timer is better. The delay function can work if the application is simple enough but might…
  • fmilburn
    fmilburn over 3 years ago in reply to WumblingBorkeys +6
    I suspect it is because the variable section1Timer is "int" while the millis() function is "unsigned long". The variable section1Timer is probably rolling over after 30 seconds or so while millis() keeps…
  • fmilburn
    fmilburn over 3 years ago in reply to shabaz +4
    Hi Shabaz, I agree it isn't that clean. Timer callbacks aren't listed in the basic Arduino reference documentation that I could see but a search turns up libraries presumably written by others such as…
Parents
  • WumblingBorkeys
    WumblingBorkeys over 3 years ago

    Well, I've gone ahead and redone most of the program trying to implement wait timers instead of delays, It works great for 30 seconds, and then something breaks... It's an older board like 5-10 years, Arduino Uno REV3. It fails in any state (see below) and quits printing "if 5" & "if 7" as it would normally every 15~ state prints.

    I've run it multiple times each with a different tripcount, and even tried not incrementing/tripping any sensors till 1minute+ it would change states once and then continue printing the same state... is there something I've missed?

    22:27:07.757 -> 0
    22:27:07.831 -> 0
    22:27:07.831 -> 0
    22:27:07.831 -> 0
    22:27:07.853 -> 0
    22:27:07.899 -> 0
    22:27:07.899 -> 0
    22:27:07.945 -> 0
    22:27:07.991 -> 0
    22:27:07.991 -> 0
    22:27:08.036 -> 0
    22:27:08.036 -> 0
    22:27:08.082 -> 0
    22:27:08.082 -> 0
    22:27:08.127 -> 0
    22:27:08.127 -> 0
    22:27:08.173 -> 0
    22:27:08.173 -> 0
    22:27:08.219 -> 0
    22:27:08.219 -> 0
    22:27:08.265 -> 0
    22:27:08.265 -> 0
    22:27:08.313 -> 0
    22:27:08.313 -> 0
    22:27:08.360 -> 0
    22:27:08.360 -> 0
    22:27:08.408 -> 0
    22:27:08.408 -> 0
    22:27:08.453 -> 0
    22:27:08.453 -> 0
    22:27:08.499 -> 0
    22:27:08.499 -> 0
    22:27:08.546 -> 0
    22:27:08.546 -> 0
    22:27:08.593 -> 0
    22:27:08.638 -> 0
    22:27:08.638 -> 0
    22:27:08.685 -> 0
    22:27:08.685 -> 0
    22:27:08.732 -> 0
    22:27:08.732 -> 0
    22:27:08.777 -> 0
    22:27:08.777 -> 0
    22:27:08.834 -> 0
    22:27:08.834 -> 0
    22:27:08.834 -> 0
    22:27:08.871 -> 0
    22:27:08.916 -> 0
    22:27:08.916 -> 0
    22:27:08.961 -> 0
    22:27:08.961 -> 0
    22:27:09.006 -> 0
    22:27:09.006 -> 0
    22:27:09.051 -> 0
    22:27:09.051 -> if 1
    22:27:09.051 -> 1
    22:27:09.096 -> 1
    22:27:09.141 -> 1
    22:27:09.141 -> 1
    22:27:09.186 -> 1
    22:27:09.186 -> if 2
    22:27:09.186 -> if 3
    22:27:09.186 -> 2
    22:27:09.231 -> 2
    22:27:09.231 -> 2
    22:27:09.276 -> 2
    22:27:09.276 -> 2
    22:27:09.321 -> 2
    22:27:09.321 -> 2
    22:27:09.368 -> 2
    22:27:09.368 -> 2
    22:27:09.413 -> 2
    22:27:09.413 -> 2
    22:27:09.458 -> 2
    22:27:09.458 -> 2
    22:27:09.503 -> 2
    22:27:09.503 -> 2
    22:27:09.548 -> 2
    22:27:09.594 -> 2
    22:27:09.594 -> if 5
    22:27:09.594 -> if 7
    22:27:09.594 -> 2
    22:27:09.642 -> 2
    22:27:09.642 -> 2
    22:27:09.690 -> 2
    22:27:09.690 -> 2
    22:27:09.737 -> 2
    22:27:09.737 -> 2
    22:27:09.784 -> 2
    22:27:09.784 -> 2
    22:27:09.841 -> 2
    22:27:09.841 -> 2
    22:27:09.841 -> 2
    22:27:09.874 -> 2
    22:27:09.921 -> 2
    22:27:09.921 -> 2
    22:27:09.966 -> 2
    22:27:09.966 -> 2
    22:27:09.966 -> if 5
    22:27:09.966 -> if 7
    22:27:10.012 -> 2
    22:27:10.012 -> 2
    22:27:10.060 -> 2
    22:27:10.060 -> 2
    22:27:10.107 -> 2
    22:27:10.107 -> 2
    22:27:10.152 -> 2
    22:27:10.152 -> 2
    22:27:10.199 -> 2
    22:27:10.199 -> 2
    22:27:10.246 -> 2
    22:27:10.246 -> 2
    22:27:10.292 -> 2
    22:27:10.337 -> 2
    22:27:10.337 -> 2
    22:27:10.385 -> 2
    22:27:10.385 -> 2
    22:27:10.385 -> if 5
    22:27:10.385 -> if 7
    22:27:10.433 -> 2
    22:27:10.433 -> 2
    22:27:10.479 -> 2
    22:27:10.479 -> 2
    22:27:10.524 -> 2
    22:27:10.524 -> 2
    22:27:10.571 -> 2
    22:27:10.571 -> 2
    22:27:10.618 -> 2
    22:27:10.618 -> 2
    22:27:10.663 -> 2
    22:27:10.663 -> 2
    22:27:10.710 -> 2
    22:27:10.710 -> 2
    22:27:10.758 -> 2
    22:27:10.758 -> 2
    22:27:10.844 -> 2
    22:27:10.844 -> if 5
    22:27:10.844 -> if 6
    22:27:10.844 -> 0
    22:27:10.848 -> 0
    22:27:10.848 -> 0
    22:27:10.896 -> 0
    22:27:10.896 -> 0
    22:27:10.944 -> 0
    22:27:10.944 -> 0
    22:27:10.991 -> 0
    22:27:10.991 -> 0
    22:27:11.037 -> 0
    22:27:11.037 -> 0
    22:27:11.082 -> 0
    22:27:11.127 -> 0
    22:27:11.127 -> 0
    22:27:11.174 -> 0
    22:27:11.174 -> 0
    22:27:11.219 -> 0
    22:27:11.219 -> 0
    22:27:11.266 -> 0
    22:27:11.266 -> 0
    22:27:11.312 -> 0
    22:27:11.312 -> 0
    22:27:11.357 -> 0
    22:27:11.357 -> 0
    22:27:11.405 -> 0
    22:27:11.405 -> 0
    22:27:11.452 -> 0
    22:27:11.452 -> 0
    22:27:11.452 -> if 1
    22:27:11.498 -> 1
    22:27:11.498 -> 1
    22:27:11.545 -> 1
    22:27:11.545 -> 1
    22:27:11.592 -> 1
    22:27:11.592 -> if 2
    22:27:11.592 -> if 3
    22:27:11.592 -> 2
    22:27:11.639 -> 2
    22:27:11.639 -> 2
    22:27:11.686 -> 2
    22:27:11.686 -> 2
    22:27:11.733 -> 2
    22:27:11.733 -> 2
    22:27:11.778 -> 2
    22:27:11.849 -> 2
    22:27:11.849 -> 2
    22:27:11.849 -> 2
    22:27:11.849 -> 2
    22:27:11.917 -> 2
    22:27:11.917 -> 2
    22:27:11.964 -> 2
    22:27:11.964 -> 2
    22:27:12.012 -> 2
    22:27:12.012 -> if 5
    22:27:12.012 -> if 7
    22:27:12.012 -> 2
    22:27:12.060 -> 2
    22:27:12.060 -> 2
    22:27:12.108 -> 2
    22:27:12.108 -> 2
    22:27:12.155 -> 2
    22:27:12.155 -> 2
    22:27:12.202 -> 2
    22:27:12.202 -> 2
    22:27:12.250 -> 2
    22:27:12.250 -> 2
    22:27:12.296 -> 2
    22:27:12.296 -> 2
    22:27:12.341 -> 2
    22:27:12.341 -> 2
    22:27:12.387 -> 2
    22:27:12.387 -> 2
    22:27:12.387 -> if 5
    22:27:12.387 -> if 7
    22:27:12.434 -> 2
    22:27:12.434 -> 2
    22:27:12.481 -> 2
    22:27:12.481 -> 2
    22:27:12.526 -> 2
    22:27:12.526 -> 2
    22:27:12.573 -> 2
    22:27:12.573 -> 2
    22:27:12.620 -> 2
    22:27:12.620 -> 2
    22:27:12.665 -> 2
    22:27:12.665 -> 2
    22:27:12.713 -> 2
    22:27:12.759 -> 2
    22:27:12.759 -> 2
    22:27:12.804 -> 2
    22:27:12.804 -> 2
    22:27:12.804 -> if 5
    22:27:12.804 -> if 7
    22:27:12.861 -> 2
    22:27:12.861 -> 2
    22:27:12.861 -> 2
    22:27:12.898 -> 2
    22:27:12.942 -> 2
    22:27:12.942 -> 2
    22:27:12.988 -> 2
    22:27:12.988 -> 2
    22:27:13.035 -> 2
    22:27:13.035 -> 2
    22:27:13.083 -> 2
    22:27:13.083 -> 2
    22:27:13.129 -> 2
    22:27:13.129 -> 2
    22:27:13.174 -> 2
    22:27:13.174 -> 2
    22:27:13.220 -> 2
    22:27:13.220 -> if 5
    22:27:13.220 -> if 7
    22:27:13.220 -> 2
    22:27:13.267 -> 2
    22:27:13.267 -> 2
    22:27:13.312 -> 2
    22:27:13.312 -> 2
    22:27:13.359 -> 2
    22:27:13.407 -> 2
    22:27:13.407 -> 2
    22:27:13.407 -> 2
    22:27:13.453 -> 2
    22:27:13.498 -> 2
    22:27:13.498 -> 2
    22:27:13.544 -> 2
    22:27:13.544 -> 2
    22:27:13.590 -> 2
    22:27:13.590 -> 2
    22:27:13.636 -> 2
    22:27:13.636 -> if 5
    22:27:13.636 -> if 7
    22:27:13.636 -> 2
    22:27:13.683 -> 2
    22:27:13.683 -> 2
    22:27:13.730 -> 2
    22:27:13.730 -> 2
    22:27:13.775 -> 2
    22:27:13.775 -> 2
    22:27:13.862 -> 2
    22:27:13.862 -> 2
    22:27:13.868 -> 2
    22:27:13.868 -> 2
    22:27:13.913 -> 2
    22:27:13.913 -> 2
    22:27:13.958 -> 2
    22:27:14.006 -> 2
    22:27:14.006 -> 2
    22:27:14.054 -> 2
    22:27:14.054 -> if 5
    22:27:14.054 -> if 7
    22:27:14.054 -> 2
    22:27:14.054 -> 2
    22:27:14.101 -> 2
    22:27:14.148 -> 2
    22:27:14.148 -> 2
    22:27:14.195 -> 2
    22:27:14.195 -> 2
    22:27:14.240 -> 2
    22:27:14.240 -> 2
    22:27:14.285 -> 2
    22:27:14.285 -> 2
    22:27:14.332 -> 2
    22:27:14.332 -> 2
    22:27:14.379 -> 2
    22:27:14.379 -> 2
    22:27:14.425 -> 2
    22:27:14.425 -> 2
    22:27:14.425 -> if 5
    22:27:14.425 -> if 6
    22:27:14.471 -> 0
    22:27:14.471 -> 0
    22:27:14.518 -> 0
    22:27:14.518 -> 0
    22:27:14.563 -> 0
    22:27:14.563 -> 0
    22:27:14.608 -> 0
    22:27:14.608 -> 0
    22:27:14.655 -> 0
    22:27:14.655 -> 0
    22:27:14.702 -> 0
    22:27:14.702 -> 0
    22:27:14.747 -> 0
    22:27:14.792 -> 0
    22:27:14.792 -> 0
    22:27:14.863 -> 0
    22:27:14.863 -> 0
    22:27:14.863 -> 0
    22:27:14.884 -> 0
    22:27:14.928 -> 0
    22:27:14.928 -> 0
    22:27:14.977 -> 0
    22:27:14.977 -> 0
    22:27:15.023 -> 0
    22:27:15.023 -> 0
    22:27:15.023 -> if 1
    22:27:15.069 -> 1
    22:27:15.069 -> 1
    22:27:15.115 -> 1
    22:27:15.115 -> 1
    22:27:15.160 -> 1
    22:27:15.160 -> if 2
    22:27:15.160 -> if 3
    22:27:15.160 -> 2
    22:27:15.205 -> 2
    22:27:15.205 -> 2
    22:27:15.252 -> 2
    22:27:15.299 -> 2
    22:27:15.299 -> 2
    22:27:15.347 -> 2
    22:27:15.347 -> 2
    22:27:15.347 -> 2
    22:27:15.394 -> 2
    22:27:15.439 -> 2
    22:27:15.439 -> 2
    22:27:15.484 -> 2
    22:27:15.484 -> 2
    22:27:15.529 -> 2
    22:27:15.529 -> 2
    22:27:15.574 -> 2
    22:27:15.574 -> if 5
    22:27:15.574 -> if 7
    22:27:15.574 -> 2
    22:27:15.619 -> 2
    22:27:15.619 -> 2
    22:27:15.664 -> 2
    22:27:15.664 -> 2
    22:27:15.709 -> 2
    22:27:15.709 -> 2
    22:27:15.754 -> 2
    22:27:15.799 -> 2
    22:27:15.799 -> 2
    22:27:15.870 -> 2
    22:27:15.870 -> 2
    22:27:15.870 -> 2
    22:27:15.889 -> 2
    22:27:15.934 -> 2
    22:27:15.934 -> 2
    22:27:15.979 -> 2
    22:27:15.979 -> if 5
    22:27:15.979 -> if 6
    22:27:15.979 -> 0
    22:27:16.024 -> 0
    22:27:16.024 -> 0
    22:27:16.069 -> 0
    22:27:16.069 -> 0
    22:27:16.116 -> 0
    22:27:16.163 -> 0
    22:27:16.163 -> 0
    22:27:16.163 -> 0
    22:27:16.210 -> 0
    22:27:16.257 -> 0
    22:27:16.257 -> 0
    22:27:16.302 -> 0
    22:27:16.302 -> 0
    22:27:16.349 -> 0
    22:27:16.349 -> 0
    22:27:16.396 -> 0
    22:27:16.396 -> 0
    22:27:16.441 -> 0
    22:27:16.441 -> 0
    22:27:16.486 -> 0
    22:27:16.486 -> 0
    22:27:16.486 -> if 1
    22:27:16.532 -> 1
    22:27:16.532 -> 1
    22:27:16.576 -> 1
    22:27:16.576 -> 1
    22:27:16.622 -> 1
    22:27:16.622 -> if 2
    22:27:16.622 -> if 3
    22:27:16.622 -> 2
    22:27:16.669 -> 2
    22:27:16.669 -> 2
    22:27:16.714 -> 2
    22:27:16.761 -> 2
    22:27:16.761 -> 2
    22:27:16.807 -> 2
    22:27:16.807 -> 2
    22:27:16.880 -> 2
    22:27:16.880 -> 2
    22:27:16.880 -> 2
    22:27:16.899 -> 2
    22:27:16.946 -> 2
    22:27:16.946 -> 2
    22:27:16.993 -> 2
    22:27:16.993 -> 2
    22:27:17.040 -> 2
    22:27:17.040 -> if 5
    22:27:17.040 -> if 7
    22:27:17.040 -> 2
    22:27:17.088 -> 2
    22:27:17.088 -> 2
    22:27:17.135 -> 2
    22:27:17.135 -> 2
    22:27:17.182 -> 2
    22:27:17.182 -> 2
    22:27:17.229 -> 2
    22:27:17.229 -> 2
    22:27:17.276 -> 2
    22:27:17.276 -> 2
    22:27:17.323 -> 2
    22:27:17.323 -> 2
    22:27:17.368 -> 2
    22:27:17.368 -> 2
    22:27:17.414 -> 2
    22:27:17.414 -> 2
    22:27:17.414 -> if 5
    22:27:17.459 -> if 7
    22:27:17.459 -> 2
    22:27:17.459 -> 2
    22:27:17.506 -> 2
    22:27:17.551 -> 2
    22:27:17.551 -> 2
    22:27:17.598 -> 2
    22:27:17.598 -> 2
    22:27:17.643 -> 2
    22:27:17.643 -> 2
    22:27:17.691 -> 2
    22:27:17.691 -> 2
    22:27:17.739 -> 2
    22:27:17.739 -> 2
    22:27:17.786 -> 2
    22:27:17.786 -> 2
    22:27:17.832 -> 2
    22:27:17.832 -> 2
    22:27:17.832 -> if 5
    22:27:17.832 -> if 6
    22:27:17.888 -> 0
    22:27:17.888 -> 0
    22:27:17.926 -> 0
    22:27:17.926 -> 0
    22:27:17.973 -> 0
    22:27:17.973 -> 0
    22:27:18.020 -> 0
    22:27:18.020 -> 0
    22:27:18.065 -> 0
    22:27:18.065 -> 0
    22:27:18.111 -> 0
    22:27:18.111 -> 0
    22:27:18.158 -> 0
    22:27:18.158 -> 0
    22:27:18.205 -> 0
    22:27:18.205 -> 0
    22:27:18.250 -> 0
    22:27:18.250 -> 0
    22:27:18.297 -> 0
    22:27:18.297 -> 0
    22:27:18.342 -> 0
    22:27:18.342 -> if 1
    22:27:18.389 -> 1
    22:27:18.389 -> 1
    22:27:18.434 -> 1
    22:27:18.434 -> 1
    22:27:18.480 -> 1
    22:27:18.480 -> if 2
    22:27:18.480 -> if 3
    22:27:18.480 -> 2
    22:27:18.527 -> 2
    22:27:18.527 -> 2
    22:27:18.572 -> 2
    22:27:18.572 -> 2
    22:27:18.617 -> 2
    22:27:18.617 -> 2
    22:27:18.662 -> 2
    22:27:18.662 -> 2
    22:27:18.710 -> 2
    22:27:18.710 -> 2
    22:27:18.757 -> 2
    22:27:18.757 -> 2
    22:27:18.804 -> 2
    22:27:18.804 -> 2
    22:27:18.892 -> 2
    22:27:18.892 -> 2
    22:27:18.896 -> if 5
    22:27:18.896 -> if 7
    22:27:18.896 -> 2
    22:27:18.943 -> 2
    22:27:18.943 -> 2
    22:27:18.989 -> 2
    22:27:18.989 -> 2
    22:27:19.035 -> 2
    22:27:19.035 -> 2
    22:27:19.081 -> 2
    22:27:19.081 -> 2
    22:27:19.128 -> 2
    22:27:19.128 -> 2
    22:27:19.175 -> 2
    22:27:19.175 -> 2
    22:27:19.222 -> 2
    22:27:19.222 -> 2
    22:27:19.269 -> 2
    22:27:19.269 -> 2
    22:27:19.269 -> if 5
    22:27:19.269 -> if 7
    22:27:19.315 -> 2
    22:27:19.315 -> 2
    22:27:19.360 -> 2
    22:27:19.360 -> 2
    22:27:19.406 -> 2
    22:27:19.406 -> 2
    22:27:19.454 -> 2
    22:27:19.454 -> 2
    22:27:19.500 -> 2
    22:27:19.500 -> 2
    22:27:19.545 -> 2
    22:27:19.545 -> 2
    22:27:19.590 -> 2
    22:27:19.637 -> 2
    22:27:19.637 -> 2
    22:27:19.682 -> 2
    22:27:19.682 -> 2
    22:27:19.682 -> if 5
    22:27:19.682 -> if 7
    22:27:19.729 -> 2
    22:27:19.729 -> 2
    22:27:19.776 -> 2
    22:27:19.776 -> 2
    22:27:19.824 -> 2
    22:27:19.824 -> 2
    22:27:19.897 -> 2
    22:27:19.897 -> 2
    22:27:19.897 -> 2
    22:27:19.918 -> 2
    22:27:19.964 -> 2
    22:27:19.964 -> 2
    22:27:20.010 -> 2
    22:27:20.010 -> 2
    22:27:20.055 -> 2
    22:27:20.055 -> 2
    22:27:20.101 -> 2
    22:27:20.101 -> if 5
    22:27:20.101 -> if 7
    22:27:20.101 -> 2
    22:27:20.147 -> 2
    22:27:20.147 -> 2
    22:27:20.195 -> 2
    22:27:20.195 -> 2
    22:27:20.243 -> 2
    22:27:20.243 -> 2
    22:27:20.290 -> 2
    22:27:20.290 -> 2
    22:27:20.337 -> 2
    22:27:20.337 -> 2
    22:27:20.382 -> 2
    22:27:20.382 -> 2
    22:27:20.429 -> 2
    22:27:20.474 -> 2
    22:27:20.474 -> 2
    22:27:20.519 -> 2
    22:27:20.519 -> if 5
    22:27:20.519 -> if 7
    22:27:20.519 -> 2
    22:27:20.566 -> 2
    22:27:20.566 -> 2
    22:27:20.613 -> 2
    22:27:20.613 -> 2
    22:27:20.658 -> 2
    22:27:20.658 -> 2
    22:27:20.705 -> 2
    22:27:20.705 -> 2
    22:27:20.752 -> 2
    22:27:20.752 -> 2
    22:27:20.798 -> 2
    22:27:20.798 -> 2
    22:27:20.844 -> 2
    22:27:20.844 -> 2
    22:27:20.901 -> 2
    22:27:20.901 -> 2
    22:27:20.901 -> if 5
    22:27:20.901 -> if 7
    22:27:20.935 -> 2
    22:27:20.935 -> 2
    22:27:20.980 -> 2
    22:27:20.980 -> 2
    22:27:21.026 -> 2
    22:27:21.074 -> 2
    22:27:21.074 -> 2
    22:27:21.121 -> 2
    22:27:21.121 -> 2
    22:27:21.166 -> 2
    22:27:21.166 -> 2
    22:27:21.214 -> 2
    22:27:21.214 -> 2
    22:27:21.260 -> 2
    22:27:21.260 -> 2
    22:27:21.307 -> 2
    22:27:21.307 -> 2
    22:27:21.307 -> if 5
    22:27:21.307 -> if 7
    22:27:21.354 -> 2
    22:27:21.354 -> 2
    22:27:21.401 -> 2
    22:27:21.401 -> 2
    22:27:21.446 -> 2
    22:27:21.446 -> 2
    22:27:21.494 -> 2
    22:27:21.494 -> 2
    22:27:21.541 -> 2
    22:27:21.541 -> 2
    22:27:21.586 -> 2
    22:27:21.586 -> 2
    22:27:21.633 -> 2
    22:27:21.633 -> 2
    22:27:21.680 -> 2
    22:27:21.680 -> 2
    22:27:21.725 -> 2
    22:27:21.725 -> if 5
    22:27:21.725 -> if 6
    22:27:21.725 -> 0
    22:27:21.772 -> 0
    22:27:21.772 -> 0
    22:27:21.817 -> 0
    22:27:21.906 -> 0
    22:27:21.906 -> 0
    22:27:21.911 -> 0
    22:27:21.911 -> 0
    22:27:21.957 -> 0
    22:27:21.957 -> 0
    22:27:22.004 -> 0
    22:27:22.004 -> 0
    22:27:22.051 -> 0
    22:27:22.051 -> 0
    22:27:22.097 -> 0
    22:27:22.097 -> 0
    22:27:22.145 -> 0
    22:27:22.145 -> if 1
    22:27:22.145 -> 1
    22:27:22.191 -> 1
    22:27:22.191 -> 1
    22:27:22.237 -> 1
    22:27:22.237 -> 1
    22:27:22.237 -> if 2
    22:27:22.237 -> if 3
    22:27:22.283 -> 2
    22:27:22.283 -> 2
    22:27:22.329 -> 2
    22:27:22.329 -> 2
    22:27:22.375 -> 2
    22:27:22.375 -> 2
    22:27:22.421 -> 2
    22:27:22.421 -> 2
    22:27:22.466 -> 2
    22:27:22.466 -> 2
    22:27:22.512 -> 2
    22:27:22.560 -> 2
    22:27:22.560 -> 2
    22:27:22.560 -> 2
    22:27:22.607 -> 2
    22:27:22.654 -> 2
    22:27:22.654 -> 2
    22:27:22.654 -> if 5
    22:27:22.654 -> if 7
    22:27:22.701 -> 2
    22:27:22.701 -> 2
    22:27:22.747 -> 2
    22:27:22.747 -> 2
    22:27:22.795 -> 2
    22:27:22.795 -> 2
    22:27:22.840 -> 2
    22:27:22.840 -> 2
    22:27:22.914 -> 2
    22:27:22.914 -> 2
    22:27:22.914 -> 2
    22:27:22.935 -> 2
    22:27:22.981 -> 2
    22:27:22.981 -> 2
    22:27:23.027 -> 2
    22:27:23.027 -> 2
    22:27:23.074 -> 2
    22:27:23.074 -> if 5
    22:27:23.074 -> if 7
    22:27:23.074 -> 2
    22:27:23.120 -> 2
    22:27:23.120 -> 2
    22:27:23.165 -> 2
    22:27:23.165 -> 2
    22:27:23.210 -> 2
    22:27:23.210 -> 2
    22:27:23.255 -> 2
    22:27:23.302 -> 2
    22:27:23.302 -> 2
    22:27:23.347 -> 2
    22:27:23.347 -> 2
    22:27:23.394 -> 2
    22:27:23.394 -> 2
    22:27:23.442 -> 2
    22:27:23.442 -> 2
    22:27:23.489 -> 2
    22:27:23.489 -> if 5
    22:27:23.489 -> if 6
    22:27:23.489 -> 0
    22:27:23.535 -> 0
    22:27:23.535 -> 0
    22:27:23.580 -> 0
    22:27:23.580 -> 0
    22:27:23.627 -> 0
    22:27:23.627 -> 0
    22:27:23.674 -> 0
    22:27:23.674 -> 0
    22:27:23.721 -> 0
    22:27:23.721 -> 0
    22:27:23.769 -> 0
    22:27:23.769 -> 0
    22:27:23.816 -> 0
    22:27:23.816 -> 0
    22:27:23.863 -> 0
    22:27:23.863 -> 0
    22:27:23.920 -> 0
    22:27:23.920 -> 0
    22:27:23.957 -> 0
    22:27:23.957 -> 0
    22:27:24.005 -> 0
    22:27:24.005 -> if 1
    22:27:24.005 -> 1
    22:27:24.052 -> 1
    22:27:24.052 -> 1
    22:27:24.099 -> 1
    22:27:24.099 -> 1
    22:27:24.146 -> if 2
    22:27:24.146 -> if 3
    22:27:24.146 -> 2
    22:27:24.146 -> 2
    22:27:24.191 -> 2
    22:27:24.238 -> 2
    22:27:24.238 -> 2
    22:27:24.285 -> 2
    22:27:24.285 -> 2
    22:27:24.331 -> 2
    22:27:24.331 -> 2
    22:27:24.378 -> 2
    22:27:24.378 -> 2
    22:27:24.424 -> 2
    22:27:24.424 -> 2
    22:27:24.470 -> 2
    22:27:24.470 -> 2
    22:27:24.517 -> 2
    22:27:24.517 -> 2
    22:27:24.517 -> if 5
    22:27:24.517 -> if 7
    22:27:24.562 -> 2
    22:27:24.562 -> 2
    22:27:24.607 -> 2
    22:27:24.607 -> 2
    22:27:24.654 -> 2
    22:27:24.654 -> 2
    22:27:24.701 -> 2
    22:27:24.701 -> 2
    22:27:24.748 -> 2
    22:27:24.748 -> 2
    22:27:24.795 -> 2
    22:27:24.795 -> 2
    22:27:24.842 -> 2
    22:27:24.842 -> 2
    22:27:24.928 -> 2
    22:27:24.928 -> 2
    22:27:24.932 -> 2
    22:27:24.932 -> if 5
    22:27:24.932 -> if 7
    22:27:24.978 -> 2
    22:27:24.978 -> 2
    22:27:25.025 -> 2
    22:27:25.025 -> 2
    22:27:25.073 -> 2
    22:27:25.073 -> 2
    22:27:25.118 -> 2
    22:27:25.118 -> 2
    22:27:25.165 -> 2
    22:27:25.165 -> 2
    22:27:25.213 -> 2
    22:27:25.213 -> 2
    22:27:25.261 -> 2
    22:27:25.261 -> 2
    22:27:25.308 -> 2
    22:27:25.308 -> 2
    22:27:25.353 -> 2
    22:27:25.353 -> if 5
    22:27:25.353 -> if 7
    22:27:25.353 -> 2
    22:27:25.401 -> 2
    22:27:25.401 -> 2
    22:27:25.446 -> 2
    22:27:25.446 -> 2
    22:27:25.491 -> 2
    22:27:25.491 -> 2
    22:27:25.536 -> 2
    22:27:25.536 -> 2
    22:27:25.581 -> 2
    22:27:25.627 -> 2
    22:27:25.627 -> 2
    22:27:25.675 -> 2
    22:27:25.675 -> 2
    22:27:25.722 -> 2
    22:27:25.722 -> 2
    22:27:25.767 -> 2
    22:27:25.767 -> if 5
    22:27:25.767 -> if 6
    22:27:25.767 -> 0
    22:27:25.814 -> 0
    22:27:25.814 -> 0
    22:27:25.859 -> 0
    22:27:25.859 -> 0
    22:27:25.932 -> 0
    22:27:25.932 -> 0
    22:27:25.932 -> 0
    22:27:25.955 -> 0
    22:27:26.002 -> 0
    22:27:26.002 -> 0
    22:27:26.047 -> 0
    22:27:26.047 -> if 1
    22:27:26.047 -> 1
    22:27:26.092 -> 1
    22:27:26.092 -> 1
    22:27:26.137 -> 1
    22:27:26.137 -> 1
    22:27:26.137 -> if 2
    22:27:26.183 -> if 3
    22:27:26.183 -> 2
    22:27:26.183 -> 2
    22:27:26.228 -> 2
    22:27:26.275 -> 2
    22:27:26.275 -> 2
    22:27:26.320 -> 2
    22:27:26.320 -> 2
    22:27:26.367 -> 2
    22:27:26.367 -> 2
    22:27:26.412 -> 2
    22:27:26.412 -> 2
    22:27:26.460 -> 2
    22:27:26.460 -> 2
    22:27:26.505 -> 2
    22:27:26.505 -> 2
    22:27:26.550 -> 2
    22:27:26.550 -> 2
    22:27:26.550 -> if 5
    22:27:26.550 -> if 7
    22:27:26.596 -> 2
    22:27:26.596 -> 2
    22:27:26.642 -> 2
    22:27:26.642 -> 2
    22:27:26.688 -> 2
    22:27:26.688 -> 2
    22:27:26.735 -> 2
    22:27:26.735 -> 2
    22:27:26.781 -> 2
    22:27:26.781 -> 2
    22:27:26.827 -> 2
    22:27:26.873 -> 2
    22:27:26.873 -> 2
    22:27:26.943 -> 2
    22:27:26.943 -> 2
    22:27:26.943 -> 2
    22:27:26.964 -> 2
    22:27:26.964 -> if 5
    22:27:26.964 -> if 7
    22:27:27.013 -> 2
    22:27:27.013 -> 2
    22:27:27.058 -> 2
    22:27:27.058 -> 2
    22:27:27.106 -> 2
    22:27:27.106 -> 2
    22:27:27.153 -> 2
    22:27:27.153 -> 2
    22:27:27.198 -> 2
    22:27:27.198 -> 2
    22:27:27.244 -> 2
    22:27:27.244 -> 2
    22:27:27.290 -> 2
    22:27:27.290 -> 2
    22:27:27.335 -> 2
    22:27:27.335 -> 2
    22:27:27.382 -> 2
    22:27:27.382 -> if 5
    22:27:27.382 -> if 7
    22:27:27.382 -> 2
    22:27:27.429 -> 2
    22:27:27.429 -> 2
    22:27:27.475 -> 2
    22:27:27.475 -> 2
    22:27:27.521 -> 2
    22:27:27.566 -> 2
    22:27:27.566 -> 2
    22:27:27.612 -> 2
    22:27:27.612 -> 2
    22:27:27.659 -> 2
    22:27:27.659 -> 2
    22:27:27.706 -> 2
    22:27:27.706 -> 2
    22:27:27.753 -> 2
    22:27:27.753 -> 2
    22:27:27.798 -> 2
    22:27:27.798 -> if 5
    22:27:27.798 -> if 7
    22:27:27.798 -> 2
    22:27:27.845 -> 2
    22:27:27.845 -> 2
    22:27:27.890 -> 2
    22:27:27.890 -> 2
    22:27:27.947 -> 2
    22:27:27.947 -> 2
    22:27:27.983 -> 2
    22:27:27.983 -> 2
    22:27:28.029 -> 2
    22:27:28.029 -> 2
    22:27:28.076 -> 2
    22:27:28.076 -> 2
    22:27:28.124 -> 2
    22:27:28.124 -> 2
    22:27:28.169 -> 2
    22:27:28.169 -> 2
    22:27:28.216 -> if 5
    22:27:28.216 -> if 6
    22:27:28.216 -> 0
    22:27:28.216 -> 0
    22:27:28.264 -> 0
    22:27:28.311 -> 0
    22:27:28.311 -> 0
    22:27:28.358 -> 0
    22:27:28.358 -> 0
    22:27:28.404 -> 0
    22:27:28.404 -> 0
    22:27:28.449 -> 0
    22:27:28.449 -> 0
    22:27:28.495 -> 0
    22:27:28.495 -> 0
    22:27:28.540 -> 0
    22:27:28.540 -> 0
    22:27:28.587 -> 0
    22:27:28.587 -> 0
    22:27:28.633 -> 0
    22:27:28.633 -> 0
    22:27:28.681 -> 0
    22:27:28.681 -> 0
    22:27:28.728 -> 0
    22:27:28.728 -> 0
    22:27:28.773 -> 0
    22:27:28.773 -> 0
    22:27:28.820 -> 0
    22:27:28.820 -> 0
    22:27:28.865 -> 0
    22:27:28.865 -> 0
    22:27:28.954 -> 0
    22:27:28.954 -> 0
    22:27:28.960 -> 0
    22:27:29.007 -> 0
    22:27:29.007 -> 0
    22:27:29.007 -> 0
    22:27:29.054 -> 0
    22:27:29.099 -> 0
    22:27:29.099 -> 0
    22:27:29.147 -> 0
    22:27:29.147 -> 0
    22:27:29.193 -> 0
    22:27:29.193 -> 0
    22:27:29.238 -> 0
    22:27:29.238 -> 0
    22:27:29.284 -> 0
    22:27:29.284 -> 0
    22:27:29.331 -> 0
    22:27:29.331 -> 0
    22:27:29.378 -> 0
    22:27:29.378 -> 0
    22:27:29.423 -> 0
    22:27:29.423 -> 0
    22:27:29.470 -> 0
    22:27:29.470 -> 0
    22:27:29.517 -> 0
    22:27:29.517 -> 0
    22:27:29.564 -> 0
    22:27:29.564 -> 0
    22:27:29.609 -> 0
    22:27:29.609 -> 0
    22:27:29.656 -> 0
    22:27:29.656 -> 0
    22:27:29.701 -> 0
    22:27:29.746 -> 0
    22:27:29.746 -> 0
    22:27:29.794 -> 0
    22:27:29.794 -> 0
    22:27:29.840 -> 0
    22:27:29.840 -> 0
    22:27:29.888 -> 0
    22:27:29.888 -> 0
    22:27:29.961 -> 0
    22:27:29.961 -> 0
    22:27:29.961 -> 0
    22:27:29.983 -> 0
    22:27:30.029 -> 0
    22:27:30.029 -> 0
    22:27:30.074 -> 0
    22:27:30.074 -> 0
    22:27:30.119 -> 0
    22:27:30.119 -> 0
    22:27:30.164 -> 0
    22:27:30.164 -> 0
    22:27:30.210 -> 0
    22:27:30.210 -> 0
    22:27:30.254 -> 0
    22:27:30.254 -> 0
    22:27:30.300 -> 0
    22:27:30.346 -> 0
    22:27:30.346 -> 0
    22:27:30.393 -> 0
    22:27:30.393 -> 0
    22:27:30.439 -> 0
    22:27:30.439 -> 0
    22:27:30.485 -> 0
    22:27:30.485 -> 0
    22:27:30.532 -> 0
    22:27:30.532 -> 0
    22:27:30.577 -> 0
    22:27:30.577 -> 0
    22:27:30.624 -> 0
    22:27:30.624 -> 0
    22:27:30.671 -> 0
    22:27:30.671 -> 0
    22:27:30.718 -> 0
    22:27:30.718 -> if 1
    22:27:30.718 -> 1
    22:27:30.765 -> 1
    22:27:30.765 -> 1
    22:27:30.812 -> 1
    22:27:30.812 -> 1
    22:27:30.812 -> if 2
    22:27:30.860 -> if 3
    22:27:30.860 -> 2
    22:27:30.860 -> 2
    22:27:30.907 -> 2
    22:27:30.907 -> 2
    22:27:30.964 -> 2
    22:27:30.964 -> 2
    22:27:31.000 -> 2
    22:27:31.000 -> 2
    22:27:31.048 -> 2
    22:27:31.048 -> 2
    22:27:31.095 -> 2
    22:27:31.095 -> 2
    22:27:31.142 -> 2
    22:27:31.142 -> 2
    22:27:31.189 -> 2
    22:27:31.189 -> 2
    22:27:31.236 -> 2
    22:27:31.236 -> if 5
    22:27:31.236 -> if 7
    22:27:31.236 -> 2
    22:27:31.284 -> 2
    22:27:31.284 -> 2
    22:27:31.330 -> 2
    22:27:31.375 -> 2
    22:27:31.375 -> 2
    22:27:31.421 -> 2
    22:27:31.421 -> 2
    22:27:31.469 -> 2
    22:27:31.469 -> 2
    22:27:31.516 -> 2
    22:27:31.516 -> 2
    22:27:31.561 -> 2
    22:27:31.561 -> 2
    22:27:31.609 -> 2
    22:27:31.609 -> 2
    22:27:31.655 -> 2
    22:27:31.655 -> if 5
    22:27:31.655 -> if 7
    22:27:31.655 -> 2
    22:27:31.702 -> 2
    22:27:31.702 -> 2
    22:27:31.749 -> 2
    22:27:31.749 -> 2
    22:27:31.796 -> 2
    22:27:31.796 -> 2
    22:27:31.843 -> 2
    22:27:31.843 -> 2
    22:27:31.890 -> 2
    22:27:31.890 -> 2
    22:27:31.976 -> 2
    22:27:31.976 -> 2
    22:27:31.976 -> 2
    22:27:31.976 -> 2
    22:27:32.029 -> 2
    22:27:32.029 -> 2
    22:27:32.076 -> if 5
    22:27:32.076 -> if 7
    22:27:32.076 -> 2
    22:27:32.076 -> 2
    22:27:32.123 -> 2
    22:27:32.123 -> 2
    22:27:32.168 -> 2
    22:27:32.213 -> 2
    22:27:32.213 -> 2
    22:27:32.258 -> 2
    22:27:32.258 -> 2
    22:27:32.303 -> 2
    22:27:32.303 -> 2
    22:27:32.350 -> 2
    22:27:32.350 -> 2
    22:27:32.398 -> 2
    22:27:32.398 -> 2
    22:27:32.447 -> 2
    22:27:32.447 -> 2
    22:27:32.447 -> if 5
    22:27:32.447 -> if 7
    22:27:32.495 -> 2
    22:27:32.495 -> 2
    22:27:32.542 -> 2
    22:27:32.542 -> 2
    22:27:32.587 -> 2
    22:27:32.587 -> 2
    22:27:32.633 -> 2
    22:27:32.633 -> 2
    22:27:32.679 -> 2
    22:27:32.679 -> 2
    22:27:32.726 -> 2
    22:27:32.726 -> 2
    22:27:32.773 -> 2
    22:27:32.773 -> 2
    22:27:32.821 -> 2
    22:27:32.821 -> 2
    22:27:32.868 -> 2
    22:27:32.868 -> if 5
    22:27:32.868 -> if 6
    22:27:32.868 -> 0
    22:27:32.913 -> 0
    22:27:32.985 -> 0
    22:27:32.985 -> 0
    22:27:32.985 -> 0
    22:27:32.985 -> 0
    22:27:33.051 -> 0
    22:27:33.051 -> 0
    22:27:33.096 -> 0
    22:27:33.096 -> 0
    22:27:33.141 -> 0
    22:27:33.141 -> 0
    22:27:33.186 -> 0
    22:27:33.186 -> 0
    22:27:33.231 -> 0
    22:27:33.231 -> 0
    22:27:33.276 -> 0
    22:27:33.276 -> 0
    22:27:33.323 -> 0
    22:27:33.323 -> 0
    22:27:33.370 -> 0
    22:27:33.370 -> 0
    22:27:33.415 -> 0
    22:27:33.415 -> 0
    22:27:33.461 -> 0
    22:27:33.506 -> 0
    22:27:33.506 -> 0
    22:27:33.552 -> 0
    22:27:33.552 -> 0
    22:27:33.598 -> 0
    22:27:33.598 -> 0
    22:27:33.643 -> 0
    22:27:33.643 -> 0
    22:27:33.688 -> 0
    22:27:33.688 -> 0
    22:27:33.733 -> 0
    22:27:33.733 -> 0
    22:27:33.778 -> 0
    22:27:33.778 -> 0
    22:27:33.824 -> 0
    22:27:33.824 -> 0
    22:27:33.870 -> 0
    22:27:33.870 -> 0
    22:27:33.915 -> 0
    22:27:33.988 -> 0
    22:27:33.988 -> 0
    22:27:33.988 -> 0
    22:27:34.011 -> 0
    22:27:34.057 -> 0
    22:27:34.057 -> 0
    22:27:34.102 -> 0
    22:27:34.102 -> 0
    22:27:34.147 -> 0
    22:27:34.147 -> 0
    22:27:34.193 -> 0
    22:27:34.193 -> 0
    22:27:34.239 -> 0
    22:27:34.239 -> 0
    22:27:34.286 -> 0
    22:27:34.286 -> 0
    22:27:34.333 -> 0
    22:27:34.333 -> 0
    22:27:34.381 -> 0
    22:27:34.381 -> 0
    22:27:34.427 -> 0
    22:27:34.427 -> 0
    22:27:34.474 -> 0
    22:27:34.474 -> 0
    22:27:34.521 -> 0
    22:27:34.521 -> 0
    22:27:34.568 -> 0
    22:27:34.568 -> 0
    22:27:34.615 -> 0
    22:27:34.615 -> 0
    22:27:34.663 -> 0
    22:27:34.663 -> 0
    22:27:34.711 -> 0
    22:27:34.711 -> 0
    22:27:34.759 -> 0
    22:27:34.759 -> 0
    22:27:34.805 -> 0
    22:27:34.805 -> 0
    22:27:34.852 -> 0
    22:27:34.852 -> 0
    22:27:34.899 -> 0
    22:27:34.947 -> 0
    22:27:34.947 -> 0
    22:27:34.947 -> 0
    22:27:35.002 -> 0
    22:27:35.002 -> 0
    22:27:35.038 -> 0
    22:27:35.083 -> 0
    22:27:35.083 -> 0
    22:27:35.129 -> 0
    22:27:35.129 -> 0
    22:27:35.175 -> 0
    22:27:35.175 -> 0
    22:27:35.221 -> 0
    22:27:35.221 -> 0
    22:27:35.268 -> 0
    22:27:35.268 -> 0
    22:27:35.313 -> 0
    22:27:35.313 -> 0
    22:27:35.360 -> 0
    22:27:35.360 -> 0
    22:27:35.406 -> 0
    22:27:35.406 -> 0
    22:27:35.453 -> 0
    22:27:35.453 -> 0
    22:27:35.498 -> 0
    22:27:35.498 -> 0
    22:27:35.543 -> 0
    22:27:35.590 -> 0
    22:27:35.590 -> if 1
    22:27:35.590 -> 1
    22:27:35.635 -> 1
    22:27:35.635 -> 1
    22:27:35.682 -> 1
    22:27:35.682 -> 1
    22:27:35.682 -> if 2
    22:27:35.682 -> if 3
    22:27:35.727 -> 2
    22:27:35.727 -> 2
    22:27:35.774 -> 2
    22:27:35.774 -> 2
    22:27:35.820 -> 2
    22:27:35.820 -> 2
    22:27:35.866 -> 2
    22:27:35.913 -> 2
    22:27:35.913 -> 2
    22:27:35.959 -> 2
    22:27:35.959 -> 2
    22:27:36.015 -> 2
    22:27:36.015 -> 2
    22:27:36.049 -> 2
    22:27:36.049 -> 2
    22:27:36.095 -> 2
    22:27:36.095 -> if 5
    22:27:36.095 -> if 7
    22:27:36.141 -> 2
    22:27:36.141 -> 2
    22:27:36.187 -> 2
    22:27:36.187 -> 2
    22:27:36.233 -> 2
    22:27:36.233 -> 2
    22:27:36.279 -> 2
    22:27:36.279 -> 2
    22:27:36.325 -> 2
    22:27:36.371 -> 2
    22:27:36.371 -> 2
    22:27:36.418 -> 2
    22:27:36.418 -> 2
    22:27:36.463 -> 2
    22:27:36.463 -> 2
    22:27:36.509 -> 2
    22:27:36.509 -> if 5
    22:27:36.509 -> if 7
    22:27:36.509 -> 2
    22:27:36.555 -> 2
    22:27:36.602 -> 2
    22:27:36.602 -> 2
    22:27:36.647 -> 2
    22:27:36.647 -> 2
    22:27:36.694 -> 2
    22:27:36.694 -> 2
    22:27:36.739 -> 2
    22:27:36.739 -> 2
    22:27:36.784 -> 2
    22:27:36.831 -> 2
    22:27:36.831 -> 2
    22:27:36.877 -> 2
    22:27:36.877 -> 2
    22:27:36.924 -> 2
    22:27:36.924 -> if 5
    22:27:36.924 -> if 6
    22:27:36.924 -> 0
    22:27:36.971 -> 0
    22:27:36.971 -> 0
    22:27:37.028 -> 0
    22:27:37.028 -> 0
    22:27:37.063 -> 0
    22:27:37.110 -> 0
    22:27:37.110 -> 0
    22:27:37.155 -> 0
    22:27:37.155 -> 0
    22:27:37.201 -> 0
    22:27:37.201 -> 0
    22:27:37.249 -> 0
    22:27:37.249 -> 0
    22:27:37.295 -> 0
    22:27:37.341 -> 0
    22:27:37.341 -> 0
    22:27:37.388 -> 0
    22:27:37.388 -> 0
    22:27:37.435 -> 0
    22:27:37.435 -> 0
    22:27:37.482 -> 0
    22:27:37.482 -> 0
    22:27:37.528 -> 0
    22:27:37.528 -> 0
    22:27:37.574 -> 0
    22:27:37.621 -> 0
    22:27:37.621 -> 0
    22:27:37.667 -> 0
    22:27:37.667 -> 0
    22:27:37.713 -> 0
    22:27:37.713 -> 0
    22:27:37.759 -> 0
    22:27:37.759 -> 0
    22:27:37.807 -> 0
    22:27:37.855 -> 0
    22:27:37.855 -> 0
    22:27:37.902 -> 0
    22:27:37.902 -> 0
    22:27:37.948 -> 0
    22:27:37.948 -> 0
    22:27:38.035 -> 0
    22:27:38.035 -> 0
    22:27:38.039 -> 0
    22:27:38.039 -> 0
    22:27:38.084 -> 0
    22:27:38.129 -> 0
    22:27:38.129 -> 0
    22:27:38.176 -> 0
    22:27:38.176 -> 0
    22:27:38.223 -> 0
    22:27:38.223 -> 0
    22:27:38.270 -> 0
    22:27:38.270 -> 0
    22:27:38.318 -> 0
    22:27:38.318 -> 0
    22:27:38.365 -> 0
    22:27:38.412 -> 0
    22:27:38.412 -> 0
    22:27:38.459 -> 0
    22:27:38.459 -> 0
    22:27:38.506 -> 0
    22:27:38.506 -> 0
    22:27:38.553 -> 0
    22:27:38.553 -> 0
    22:27:38.598 -> 0
    22:27:38.598 -> 0
    22:27:38.643 -> 0
    22:27:38.691 -> 0
    22:27:38.691 -> 0
    22:27:38.737 -> 0
    22:27:38.737 -> 0
    22:27:38.782 -> 0
    22:27:38.782 -> 0
    22:27:38.828 -> 0
    22:27:38.828 -> 0
    22:27:38.876 -> 0
    22:27:38.923 -> 0
    22:27:38.923 -> if 1
    22:27:38.923 -> 1
    22:27:38.970 -> 1
    22:27:38.970 -> 1
    22:27:39.044 -> 1
    22:27:39.044 -> if 2
    22:27:39.044 -> if 3
    22:27:39.044 -> 2
    22:27:39.044 -> 2
    22:27:39.065 -> 2
    22:27:39.112 -> 2
    22:27:39.112 -> 2
    22:27:39.157 -> 2
    22:27:39.157 -> 2
    22:27:39.203 -> 2
    22:27:39.249 -> 2
    22:27:39.249 -> 2
    22:27:39.296 -> 2
    22:27:39.296 -> 2
    22:27:39.342 -> 2
    22:27:39.342 -> 2
    22:27:39.390 -> 2
    22:27:39.390 -> 2
    22:27:39.390 -> if 5
    22:27:39.435 -> if 7
    22:27:39.435 -> 2
    22:27:39.482 -> 2
    22:27:39.482 -> 2
    22:27:39.529 -> 2
    22:27:39.529 -> 2
    22:27:39.576 -> 2
    22:27:39.576 -> 2
    22:27:39.623 -> 2
    22:27:39.623 -> 2
    22:27:39.670 -> 2
    22:27:39.670 -> 2
    22:27:39.717 -> 2
    22:27:39.717 -> 2
    22:27:39.762 -> 2
    22:27:39.810 -> 2
    22:27:39.810 -> 2
    22:27:39.856 -> 2
    22:27:39.856 -> 2
    22:27:39.902 -> 2
    22:27:39.902 -> 2
    22:27:39.948 -> 2
    22:27:39.948 -> 2
    22:27:39.994 -> 2
    22:27:40.051 -> 2
    22:27:40.051 -> 2
    22:27:40.051 -> 2
    22:27:40.088 -> 2
    22:27:40.135 -> 2
    22:27:40.135 -> 2
    22:27:40.180 -> 2
    22:27:40.180 -> 2
    22:27:40.225 -> 2
    22:27:40.272 -> 2
    22:27:40.272 -> 2
    22:27:40.317 -> 2
    22:27:40.317 -> 2
    22:27:40.362 -> 2
    22:27:40.362 -> 2
    22:27:40.407 -> 2
    22:27:40.407 -> 2
    22:27:40.452 -> 2
    22:27:40.499 -> 2
    22:27:40.499 -> 2
    22:27:40.545 -> 2
    22:27:40.545 -> 2
    22:27:40.591 -> 2
    22:27:40.591 -> 2
    22:27:40.636 -> 2
    22:27:40.636 -> 2
    22:27:40.684 -> 2
    22:27:40.684 -> 2
    22:27:40.730 -> 2
    22:27:40.776 -> 2
    22:27:40.776 -> 2
    22:27:40.822 -> 2
    22:27:40.822 -> 2
    22:27:40.868 -> 2
    22:27:40.868 -> 2
    22:27:40.914 -> 2
    22:27:40.914 -> 2
    22:27:40.961 -> 2
    22:27:41.006 -> 2
    22:27:41.006 -> 2
    22:27:41.063 -> 2
    22:27:41.063 -> 2
    22:27:41.100 -> 2
    22:27:41.100 -> 2
    22:27:41.145 -> 2
    22:27:41.145 -> 2
    22:27:41.192 -> 2
    22:27:41.237 -> 2
    22:27:41.237 -> 2
    22:27:41.285 -> 2
    22:27:41.285 -> 2
    22:27:41.332 -> 2
    22:27:41.332 -> 2
    22:27:41.379 -> 2
    22:27:41.379 -> 2
    22:27:41.424 -> 2
    22:27:41.470 -> 2
    22:27:41.470 -> 2
    22:27:41.515 -> 2
    22:27:41.515 -> 2
    22:27:41.561 -> 2
    22:27:41.561 -> 2
    22:27:41.609 -> 2
    22:27:41.609 -> 2
    22:27:41.656 -> 2
    22:27:41.656 -> 2
    22:27:41.702 -> 2
    22:27:41.747 -> 2
    22:27:41.747 -> 2
    22:27:41.793 -> 2
    22:27:41.793 -> 2
    22:27:41.840 -> 2
    22:27:41.840 -> 2
    22:27:41.887 -> 2
    22:27:41.887 -> 2
    22:27:41.934 -> 2
    22:27:41.934 -> 2
    22:27:41.980 -> 2
    22:27:42.068 -> 2
    22:27:42.068 -> 2
    22:27:42.074 -> 2
    22:27:42.074 -> 2
    22:27:42.121 -> 2
    22:27:42.121 -> 2
    22:27:42.167 -> 2
    22:27:42.167 -> 2
    22:27:42.212 -> 2
    22:27:42.212 -> 2
    22:27:42.259 -> 2
    22:27:42.304 -> 2
    22:27:42.304 -> 2
    22:27:42.349 -> 2
    22:27:42.349 -> 2
    22:27:42.394 -> 2
    22:27:42.394 -> 2
    22:27:42.439 -> 2
    22:27:42.486 -> 2
    22:27:42.486 -> 2
    22:27:42.531 -> 2
    22:27:42.531 -> 2
    22:27:42.576 -> 2
    22:27:42.576 -> 2
    22:27:42.621 -> 2
    22:27:42.621 -> 2
    22:27:42.668 -> 2
    22:27:42.713 -> 2
    22:27:42.713 -> 2
    22:27:42.762 -> 2
    22:27:42.762 -> 2
    22:27:42.808 -> 2
    22:27:42.808 -> 2
    22:27:42.856 -> 2
    22:27:42.856 -> 2
    22:27:42.901 -> 2
    22:27:42.901 -> 2
    22:27:42.949 -> 2
    22:27:42.994 -> 2
    22:27:42.994 -> 2
    22:27:43.081 -> 2
    22:27:43.081 -> 2
    22:27:43.088 -> 2
    22:27:43.088 -> 2
    22:27:43.135 -> 2
    22:27:43.135 -> 2
    22:27:43.181 -> 2
    22:27:43.227 -> 2
    22:27:43.227 -> 2
    22:27:43.274 -> 2
    22:27:43.274 -> 2
    22:27:43.321 -> 2
    22:27:43.321 -> 2
    22:27:43.366 -> 2
    22:27:43.366 -> 2
    22:27:43.413 -> 2
    22:27:43.413 -> 2
    22:27:43.458 -> 2
    22:27:43.503 -> 2
    22:27:43.503 -> 2
    22:27:43.551 -> 2
    22:27:43.551 -> 2
    22:27:43.598 -> 2
    22:27:43.598 -> 2
    22:27:43.645 -> 2
    22:27:43.645 -> 2
    22:27:43.692 -> 2
    22:27:43.692 -> 2
    22:27:43.738 -> 2
    
    #include <FastLED.h>
    #include <Wire.h> 
    #include <LiquidCrystal_I2C.h>
    //------------------------Lights int-----------------
    #define NUM_LEDS 25
    #define DATA_PIN 12
    #define COLOR_ORDER GRB
    #define CHIPSET WS2812B
    #define BRIGHTNESS 060
    #define VOLTS 5
    #define MAX_AMPS 500
    CRGB leds[NUM_LEDS];
    //-----------------------------------------------------
    
    //--------------timer-----------
    int section1Timer;
    int timeDelay = 100;
    int tripCheck = 400;
    //-------------------------------
    //1 is tripped zero should be normal
    //--------------Laser Int-------------------
    const int lasersens1 = 2;
    int sensSect1;
    int section1Tripped;
    const int lasersens2 = 3;
    int sensSect2;
    int section2Tripped;
    const int lasersens3 = 4;
    const int lasersens4 = 5;
    const int lasersens5 = 6;
    
    //------------------------------------------
    
    //---------------------GI/O-------- mostly not used
    const int disablebutton =10;
    int disablebuttonstate;
    int buttonpresscount =0;
    const int resetButton = 9;
    int resetButtonState = 0;
    int senssec1 = 0;
    int tripcount = 0;
    
    // Set the LCD address to 0x27 for a 16 chars and 2 line display
    LiquidCrystal_I2C lcd(0x27, 16, 2);
    
    
    void setup() {
      // put your setup code here, to run once:
     pinMode(lasersens1, INPUT);
     pinMode(lasersens2, INPUT);
     pinMode(lasersens3, INPUT);
     pinMode(lasersens4, INPUT);
     pinMode(lasersens5, INPUT);
     pinMode(resetButton, INPUT);
    
    
     
     FastLED.addLeds<CHIPSET, DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS);
     FastLED.setMaxPowerInVoltsAndMilliamps(VOLTS,MAX_AMPS);
     FastLED.setBrightness(BRIGHTNESS);
     FastLED.clear();
     FastLED.show();
    
      // initialize the LCD
      lcd.begin();
      // Turn on the blacklight and print a message.
      lcd.backlight();
    
      Serial.begin(9600);
    }
    
    
    
    void loop() {
    
    
     lcd.setCursor(0, 0);
     lcd.print("Times Tripped");
     lcd.setCursor(0, 1);
     lcd.print(tripcount);
    //Serial.println("start");
    Serial.println(section1Tripped);//denotes state at beginning of cycles
    
    if(section1Tripped == 0) //defualt state
    {
      sensSect1 = digitalRead(lasersens1)+ digitalRead(lasersens2);
      //Serial.println(sensSect1);
      if(sensSect1 != 0)
      {
        section1Timer = millis() + timeDelay;
        section1Tripped = 1;//advances state
        Serial.println("if 1");
      }
    }
    if(section1Tripped == 1 && section1Timer < millis())
    {
    
        Serial.println("if 2");
      if(0 != digitalRead(lasersens1)+ digitalRead(lasersens2))
      {
        section1Timer = millis() + tripCheck;
        triggerLights(1); //tripped state should skip all but the last if statement turns on lights
        section1Tripped = 2;
    
        Serial.println("if 3");
      }
      else
      {
       section1Tripped = 0; //false trip-(too fast) resets state
       section1Timer = millis() + timeDelay;
    
        Serial.println("if 4");
      }
    }
    if(section1Tripped == 2 && section1Timer < millis()) //reset state
     {
    
        Serial.println("if 5");
      if(digitalRead(lasersens1) + digitalRead(lasersens2) == 0 && 0 == digitalRead(resetButton)) //lasers must be detected aswell as a button depressed
      {
     
        Serial.println("if 6");
        shutOffLights(1);//turns off lights
        section1Tripped = 0;//resets states
      }
      else
      {
        Serial.println("if 7");
       section1Timer = millis() + tripCheck;//continues triped state
      }
     }
    }
    
    int triggerLights(int x) //Trigger lights to illuminate those who tripped it
    {
    switch (x){
      case 1:
      leds[0] = CRGB (255,255,255);
      leds[1] = CRGB (255,255,255);
      leds[2] = CRGB (255,255,255);
      leds[3] = CRGB (255,255,255);
      leds[4] = CRGB (255,255,255);
      FastLED.show();
      tripcount++;
      break;
     case 2:
      leds[5] = CRGB (255,255,255);
      leds[6] = CRGB (255,255,255);
      leds[7] = CRGB (255,255,255);
      leds[8] = CRGB (255,255,255);
      leds[9] = CRGB (255,255,255);
      FastLED.show();
      tripcount++;
      break;
      default:
      break;
    
    }
    }
    int shutOffLights(int x) //shutoff lights that aren't tripped anymore
    {
    switch (x){
      case 1:
      leds[0] = CRGB (0,0,0);
      leds[1] = CRGB (0,0,0);
      leds[2] = CRGB (0,0,0);
      leds[3] = CRGB (0,0,0);
      leds[4] = CRGB (0,0,0);
      FastLED.show();
      break;
     case 2:
      leds[5] = CRGB (0,0,0);
      leds[6] = CRGB (0,0,0);
      leds[7] = CRGB (0,0,0);
      leds[8] = CRGB (0,0,0);
      leds[9] = CRGB (0,0,0);
      FastLED.show();
      break;
      default:
      break;
    
    }
    }
    

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • fmilburn
    fmilburn over 3 years ago in reply to WumblingBorkeys

    I suspect it is because the variable section1Timer is "int" while the millis() function is "unsigned long".  The variable section1Timer is probably rolling over after 30 seconds or so while millis() keeps counting.  So, try making time related variables like this: 

    unsigned long section1Timer;

    After about 50 days an unsigned long variable will roll over.  That can be handled as described here:  https://arduino.stackexchange.com/questions/12587/how-can-i-handle-the-millis-rollover

    If you want to get fancy, you can make a state machine as described here:  https://learn.adafruit.com/multi-tasking-the-arduino-part-1/ditch-the-delay?view=all

    • Cancel
    • Vote Up +6 Vote Down
    • Sign in to reply
    • Cancel
  • neilk
    neilk over 3 years ago in reply to fmilburn

    Hi Frank - I've used timers a lot to do a bit of multitasking. However, that link to the adafruit tutorial is magnificent!!

    Thanks for posting that

    Neil

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • fmilburn
    fmilburn over 3 years ago in reply to neilk

    :-)

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • WumblingBorkeys
    WumblingBorkeys over 3 years ago in reply to fmilburn

    Worked like a charm thanks! I'll work on using a state machine!

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • shabaz
    shabaz over 3 years ago in reply to fmilburn

    I'm finding that adafruit article the complete opposite, really weird. It's a strange pattern they are using. 

    It's a strange mix of using the traditional loop() while repeatedly checking if a time has expired (i.e. they are constantly polling). Does the Arduino support timer callback?

    If so, then a more normal method would be to set up a timer tick, so that nothing is needed in loop(), and instead everything is event-driven, either a timer event, or an external event (e.g. button-press).

    A cut-down method would be to just directly act on the tick, whereas a more complete way would be to add an event to a queue (ordinarily the OS supports that, but the Arduino has a very cut-down OS so I wouldn't expect it).

    I'm not mega-familiar with Arduino, so I don't know if the article does it the way it did to work around any specific limitations or issues. In essence, they have taken an understandable loop (which to be fair, is still used in commercial code, even military code), and made it unintuitive to follow code because now you'd need to search every function to see if it actually does anything, when looking at the code in the loop.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Cancel
  • fmilburn
    fmilburn over 3 years ago in reply to shabaz

    Hi Shabaz,

    I agree it isn't that clean.  Timer callbacks aren't listed in the basic Arduino reference documentation that I could see but a search turns up libraries presumably written by others such as this one:  https://github.com/cygig/TimerEvent and https://www.arduino.cc/reference/en/libraries/timeinterrupt/.  Maybe Adafruit was trying to stick directly to what is documented in the basic reference material and also it was written some time back.

    I was trying to think of some code I might have written that does something similar with Arduino but couldn't think of anything.  The AIS Alarm that I documented here on e14 uses the hardware timers on the MSP430 directly and not the Arduino libraries.

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Cancel
  • WumblingBorkeys
    WumblingBorkeys over 3 years ago in reply to fmilburn

    I've started to Class-based program and I'm into an issue with my overloaded constructors...

    I want to make a section of lasers/ laser-detectors into a class and then just call an update loop for each section.

    I figured that I could probably call the constructor within another constructor to eliminate duplicated code but now I am getting --

    "declaration of 'senssector pin1' shadows a parameter" error
    As I understand shadows a parameter means there is another 'pin1' variable somewhere which there isn't.....

    I'll attach the Class alone and the rest of the code in another imbed.

    class senssector
    {
      // Class Member Variables
      // These are initialized at startup
      int sens;      
      int tripCheck =100;     
      int triggerCheck =300;
      int trigger = 0;
      int sens1 =2;
      int sens2 =2;
      int sens3 =2;//pin 2 will  be grounded  and always report a 0/LOW
      int sens4 =2;//so if it is unuesed it will not influnce anything
      int sens5 =2;
    
      
    
      // These maintain the current state
      int laserState;                 // laserState used to set the LED
      unsigned long previousMillis;   // will store last time Update was updated
    
      // Constructor&Overloads - creates a Flasher 
      // and initializes the member variables and state
    public:
      senssector(int pin)
      {
      int sens1 = pin;
      pinMode(sens1, INPUT);
      pinMode(2,INPUT);     
     
      laserState = 0; 
      previousMillis = 0;
       }
       senssector(int pin1,int pin2)
       {
       int sens2 = pin2;     
       pinMode(sens2, INPUT);   
       senssector(pin1);
       }
         senssector(int pin3,int pin4,int pin5)
         {
         int sens3 = pin5;     
         pinMode(sens3, INPUT);    
         senssector(pin3,pin4);
         }
            senssector(int pin6,int pin7,int pin8,int pin9)
            {
            int sens4 = pin9;     
            pinMode(sens3, INPUT);   
            senssector(pin6,pin7,pin8);
            }
              senssector(int pin10,int pin11,int pin12,int pin13,int pin14)
              {
              int sens5 = pin14;       
              pinMode(sens5, INPUT);   
              senssector(pin10,pin11,pin12,pin13);
              }
    
    
    
    void Update()
      {
        // check to see if it's time to change the state of the LED
        unsigned long currentMillis = millis();
        sens = digitalRead(sens1) + digitalRead(sens2) + digitalRead(sens3) + digitalRead(sens4) + digitalRead(sens5);
        
             
        if((laserState == 0) && (currentMillis - previousMillis >= tripCheck) && (sens == 0))
        {
          laserState = 1;  // Advance laser State
          previousMillis = currentMillis;  // Remember the time
    
        }
        if ((laserState == 1) && (currentMillis - previousMillis >= tripCheck) &&(sens == 0))
        {
          laserState = 2;  //advance to trigger state
          previousMillis = currentMillis;   // Remember the time
          trigger = 1;
          return trigger;   // Update the actual LEDs
        }
        else if ((laserState == 1) && (currentMillis - previousMillis >= tripCheck) &&(sens == 1))
        {
          laserState = 0;
          previousMillis = currentMillis;
        }
        if ((laserState == 2) && (currentMillis - previousMillis >= tripCheck))
        {
          if(sens == 0 && digitalRead(resetButton) ==0)
          {
            trigger =0;
            return trigger;
            previousMillis = currentMillis; 
          }
          else
          {
           previousMillis = currentMillis;
          }
        }
      }
    };
    #include <FastLED.h>
    #include <Wire.h> 
    #include <LiquidCrystal_I2C.h>
    //------------------------Light int-----------------
    #define NUM_LEDS 25
    #define DATA_PIN 12
    #define COLOR_ORDER GRB
    #define CHIPSET WS2812B
    #define BRIGHTNESS 060
    #define VOLTS 5
    #define MAX_AMPS 500
    CRGB leds[NUM_LEDS];
    //-----------------------------------------------------
    
    //--------------timer-----------
    unsigned long section1Timer;
    
    //-------------------------------
    //1 is tripped zero should be normal
    //--------------Laser Int-------------------
    const int lasersens1 = 2;
    int sensSect1;
    int section1Tripped;
    const int lasersens2 = 3;
    int sensSect2;
    int section2Tripped;
    const int lasersens3 = 4;
    const int lasersens4 = 5;
    const int lasersens5 = 6;
    
    //------------------------------------------
    
    //---------------------GI/O-------- mostly not used
    const int disablebutton =10;
    int disablebuttonstate;
    int buttonpresscount =0;
    const int resetButton = 9;
    int resetButtonState = 0;
    int senssec1 = 0;
    int tripcount = 0;
    
    // Set the LCD address to 0x27 for a 16 chars and 2 line display
    LiquidCrystal_I2C lcd(0x27, 16, 2);
    //Class for detecting and handling laser detections------------------------------------
    class senssector
    {
      // Class Member Variables
      // These are initialized at startup
      int sens;      
      int tripCheck =100;     
      int triggerCheck =300;
      int trigger = 0;
      int sens1 =2;
      int sens2 =2;
      int sens3 =2;//pin 2 will  be grounded  and always report a 0/LOW
      int sens4 =2;//so if it is unuesed it will not influnce anything
      int sens5 =2;
    
      
    
      // These maintain the current state
      int laserState;                 // laserState used to set the LED
      unsigned long previousMillis;   // will store last time Update was updated
    
      // Constructor&Overloads - creates a Flasher 
      // and initializes the member variables and state
    public:
      senssector(int pin)
      {
      int sens1 = pin;
      pinMode(sens1, INPUT);
      pinMode(2,INPUT);     
     
      laserState = 0; 
      previousMillis = 0;
       }
       senssector(int pin1,int pin2)
       {
       int sens2 = pin2;     
       pinMode(sens2, INPUT);   
       senssector(pin1);
       }
         senssector(int pin3,int pin4,int pin5)
         {
         int sens3 = pin5;     
         pinMode(sens3, INPUT);    
         senssector(pin3,pin4);
         }
            senssector(int pin6,int pin7,int pin8,int pin9)
            {
            int sens4 = pin9;     
            pinMode(sens3, INPUT);   
            senssector(pin6,pin7,pin8);
            }
              senssector(int pin10,int pin11,int pin12,int pin13,int pin14)
              {
              int sens5 = pin14;       
              pinMode(sens5, INPUT);   
              senssector(pin10,pin11,pin12,pin13);
              }
    
    
    
    void Update()
      {
        // check to see if it's time to change the state of the LED
        unsigned long currentMillis = millis();
        sens = digitalRead(sens1) + digitalRead(sens2) + digitalRead(sens3) + digitalRead(sens4) + digitalRead(sens5);
        
             
        if((laserState == 0) && (currentMillis - previousMillis >= tripCheck) && (sens == 0))
        {
          laserState = 1;  // Advance laser State
          previousMillis = currentMillis;  // Remember the time
    
        }
        if ((laserState == 1) && (currentMillis - previousMillis >= tripCheck) &&(sens == 0))
        {
          laserState = 2;  //advance to trigger state
          previousMillis = currentMillis;   // Remember the time
          trigger = 1;
          return trigger;   // Update the actual LEDs
        }
        else if ((laserState == 1) && (currentMillis - previousMillis >= tripCheck) &&(sens == 1))
        {
          laserState = 0;
          previousMillis = currentMillis;
        }
        if ((laserState == 2) && (currentMillis - previousMillis >= tripCheck))
        {
          if(sens == 0 && digitalRead(resetButton) ==0)
          {
            trigger =0;
            return trigger;
            previousMillis = currentMillis; 
          }
          else
          {
           previousMillis = currentMillis;
          }
        }
      }
    };
    //----------------------------------------------------------------------------------------------------------
    
    void setup() {
     //intialize a sector
     senssectorone.senssector(3,4);
    
     
     pinMode(resetButton, INPUT); 
     FastLED.addLeds<CHIPSET, DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS);
     FastLED.setMaxPowerInVoltsAndMilliamps(VOLTS,MAX_AMPS);
     FastLED.setBrightness(BRIGHTNESS);
     FastLED.clear();
     FastLED.show();
    
      // initialize the LCD
      lcd.begin();
      lcd.backlight();
      Serial.begin(9600);
    }
    
    
    
    void loop() {
    
     updateLcd();
      
    
    
    }
    
    int triggerLights(int x) //Trigger lights to illuminate those who tripped it
    {
    switch (x){
      case 1:
      leds[0] = CRGB (255,255,255);
      leds[1] = CRGB (255,255,255);
      leds[2] = CRGB (255,255,255);
      leds[3] = CRGB (255,255,255);
      leds[4] = CRGB (255,255,255);
      FastLED.show();
      tripcount++;
      break;
     case 2:
      leds[5] = CRGB (255,255,255);
      leds[6] = CRGB (255,255,255);
      leds[7] = CRGB (255,255,255);
      leds[8] = CRGB (255,255,255);
      leds[9] = CRGB (255,255,255);
      FastLED.show();
      tripcount++;
      break;
      default:
      break;
    
    }
    }
    int shutOffLights(int x) //shutoff lights that aren't tripped anymore
    {
    switch (x){
      case 1:
      leds[0] = CRGB (0,0,0);
      leds[1] = CRGB (0,0,0);
      leds[2] = CRGB (0,0,0);
      leds[3] = CRGB (0,0,0);
      leds[4] = CRGB (0,0,0);
      FastLED.show();
      break;
     case 2:
      leds[5] = CRGB (0,0,0);
      leds[6] = CRGB (0,0,0);
      leds[7] = CRGB (0,0,0);
      leds[8] = CRGB (0,0,0);
      leds[9] = CRGB (0,0,0);
      FastLED.show();
      break;
      default:
      break;
    
    }
    }
    int updateLcd()
    {
     lcd.setCursor(0, 0);
     lcd.print("Times Tripped");
     lcd.setCursor(0, 1);
     lcd.print(tripcount);
    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • WumblingBorkeys
    WumblingBorkeys over 3 years ago in reply to WumblingBorkeys

    Most of my Class experience comes from C#, and I have no idea how much transfers. Also I tried implementing state-machine but I'm not to sure. my last code seemed along the lines of state-machine (at least to me) to begin with. Thanks in advanced!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • fmilburn
    fmilburn over 3 years ago in reply to WumblingBorkeys

    I basically do C programming when using microcontrollers, somewhat tainted with a bit of C++ and am self taught.  My suggestion is to whittle it down to just enough to demonstrate the error when requesting help.  Somewhat related, you have generated a lot of code in a very short period of time.  Get a simple framework working first and then add in the detail, testing as you go along.  That way you can quickly determine which line broke the code and try to determine why that is.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • WumblingBorkeys
    WumblingBorkeys over 3 years ago in reply to fmilburn

    Well, I've made a lot of progress, at this point, it's functioning! I couldn't figure out if you could call constructors from constructors but I just put in a couple of minutes to create the different constructors in their entirety. At this point, it's just adding a couple of features and getting off to the races! Thanks, SOO much fmiburn!! I'll attach what I've got and probably make a new thread when I have all I want done done, with circuit diagrams and whatnot!

    #include <FastLED.h>
    #include <Wire.h> 
    #include <LiquidCrystal_I2C.h>
    //------------------------Light int-----------------
    #define NUM_LEDS 25
    #define DATA_PIN 12
    #define COLOR_ORDER GRB
    #define CHIPSET WS2812B
    #define BRIGHTNESS 060
    #define VOLTS 5
    #define MAX_AMPS 500
    CRGB leds[NUM_LEDS];
    //-----------------------------------------------------
    //1 is no light, zero should be active
    //---------------------GI/O-------- mostly not used
    const int disablebutton =10;
    int disablebuttonstate;
    int buttonpresscount =0;
    const int resetButton =11;
    int resetButtonState = 0;
    int senssec1 = 0;
    int tripcount = 0;
    
    // Set the LCD address to 0x27 for a 16 chars and 2 line display
    LiquidCrystal_I2C lcd(0x27, 16, 2);
    //Class for detecting and handling laser detections------------------------------------
    class senssector
    {
      // Class Member Variables
      // These are initialized at startup
      int sens;      
      int tripCheck =100;     
      int triggerCheck =300;
      int trigger = 0;
      int sens1 =2;
      int sens2 =2;
      int sens3 =2;//pin 2 will  be grounded  and always report a 0/LOW
      int sens4 =2;//so if it is unuesed it will not influnce anything
      int sens5 =2;
      int sect;
    
      
    
      // These maintain the current state
      int laserState;                 // laserState used to set the LED
      unsigned long previousMillis;   // will store last time Update was updated
    
      // Constructor&Overloads - creates a Flasher 
      // and initializes the member variables and state
    public:
      senssector(int light, int pin){
      sect = light;
      sens1 = pin;
      pinMode(sens1, INPUT);
      laserState = 0; 
      previousMillis = 0;
      }
      senssector(int light,int pin,int pin1) {
    
      sect = light;
      sens2 = pin1;  
      sens1 = pin;
      pinMode(sens1, INPUT);
      pinMode(sens2, INPUT);    
      laserState = 0; 
      previousMillis = 0;
      //senssector(light1, pin1);
      }
         senssector(int light,int pin,int pin1,int pin2){
         sect = light;
         sens1 = pin;
         sens2 = pin1;
         sens3 = pin2;  
         pinMode(sens1, INPUT);
         pinMode(sens2, INPUT);
         pinMode(sens3, INPUT);       
         laserState = 0; 
         previousMillis = 0;
         }
            senssector(int light,int pin,int pin1,int pin2,int pin3)
            {
            sect = light;
            sens1 = pin;
            sens2 = pin1;
            sens3 = pin2;
            sens4 = pin3;  
            pinMode(sens1, INPUT);
            pinMode(sens2, INPUT);
            pinMode(sens3, INPUT);
            pinMode(sens4, INPUT);       
            laserState = 0; 
            previousMillis = 0;
            }
                senssector(int light,int pin,int pin1,int pin2,int pin3,int pin4)
                {
                sect = light;
                sens1 = pin;
                sens2 = pin1;
                sens3 = pin2;
                sens4 = pin3;
                sens5 = pin4;  
                pinMode(sens1, INPUT);
                pinMode(sens2, INPUT);
                pinMode(sens3, INPUT);
                pinMode(sens4, INPUT);
                pinMode(sens5, INPUT);       
                laserState = 0; 
                previousMillis = 0;
              }
    
    
    
    void poll()
      {
        Serial.println("poll");
        // check to see if it's time to change the state of the LED
        unsigned long currentMillis = millis();
        sens = digitalRead(sens1)+ digitalRead(sens2) + digitalRead(sens3) + digitalRead(sens4) + digitalRead(sens5);
        Serial.println(sens);
        
             
        if((laserState == 0) && (currentMillis - previousMillis >= tripCheck) && (sens != 0))
        {
          laserState = 1;  // Advance laser State
          previousMillis = currentMillis;  // Remember the time
    
        }
        if ((laserState == 1) && (currentMillis - previousMillis >= tripCheck) &&(sens != 0))
        {
          laserState = 2;  //advance to trigger state
          previousMillis = currentMillis;   // Remember the time
          triggerLights(sect);// Update the actual LEDs
        }
        else if ((laserState == 1) && (currentMillis - previousMillis >= tripCheck) &&(sens == 0))
        {
          laserState = 0;
          previousMillis = currentMillis;
        }
        if ((laserState == 2) && (currentMillis - previousMillis >= tripCheck))
        {
          if(sens == 0 && digitalRead(resetButton) == 0)
          {
            shutOffLights(sect);     
            previousMillis = currentMillis;
            laserState=0;
          }
          else
          {
           previousMillis = currentMillis;
          }
        }
      }
        triggerLights(int x) //Trigger lights to illuminate those who tripped it
        {
          switch (x){
          case 1:
           leds[0] = CRGB (255,255,255);
           leds[1] = CRGB (255,255,255);
           leds[2] = CRGB (255,255,255);
           leds[3] = CRGB (255,255,255);
           leds[4] = CRGB (255,255,255);
           FastLED.show();
           tripcount++;
          break;
          case 2:
            leds[5] = CRGB (255,255,255);
            leds[6] = CRGB (255,255,255);
            leds[7] = CRGB (255,255,255);
            leds[8] = CRGB (255,255,255);
            leds[9] = CRGB (255,255,255);
            FastLED.show();
            tripcount++;
           break;
           default:
           break;
    
    }
    }
     shutOffLights(int x) //shutoff lights that aren't tripped anymore
    {
    switch (x){
      case 1:
      leds[0] = CRGB (0,0,0);
      leds[1] = CRGB (0,0,0);
      leds[2] = CRGB (0,0,0);
      leds[3] = CRGB (0,0,0);
      leds[4] = CRGB (0,0,0);
      FastLED.show();
      break;
     case 2:
      leds[5] = CRGB (0,0,0);
      leds[6] = CRGB (0,0,0);
      leds[7] = CRGB (0,0,0);
      leds[8] = CRGB (0,0,0);
      leds[9] = CRGB (0,0,0);
      FastLED.show();
       break;
       default:
       break;
    
        }
      }
    };
    //----------------------------------------------------------------------------------------------------------
    //intialize a sector
    senssector senssectorone(1,3,4,5,6);
    senssector senssectortwo(2,7);
    void setup() {
    
     
    
     pinMode(2,INPUT); 
     pinMode(resetButton, INPUT); 
     FastLED.addLeds<CHIPSET, DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS);
     FastLED.setMaxPowerInVoltsAndMilliamps(VOLTS,MAX_AMPS);
     FastLED.setBrightness(BRIGHTNESS);
     FastLED.clear();
     FastLED.show();
    
      // initialize the LCD
      lcd.begin();
      lcd.backlight();
      Serial.begin(9600);
    }
    
    
    
    void loop() {
    
     updateLcd();
     senssectorone.poll();
     senssectortwo.poll();
    
      
    }
    
    int updateLcd()
    {
     lcd.setCursor(0, 0);
     lcd.print("Times Tripped");
     lcd.setCursor(0, 1);
     lcd.print(tripcount);
    }

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • fmilburn
    fmilburn over 3 years ago in reply to WumblingBorkeys

    Great!  I do hope you make a post when you are done. 

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • fmilburn
    fmilburn over 3 years ago in reply to WumblingBorkeys

    Great!  I do hope you make a post when you are done. 

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube